Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

google-java-format 1.37.0: NoSuchMethodError on JavaFormatterOptions$Style.valueOf (Style is now a record)

Đang mở Phù hợp với người mới
#3,126 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Goooler đang làm issue này rồi.

Từ ngày 3/10/2026.

  • #1472 của @Goooler — đang mở
  • #1477 của @copybara-service — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu tại GoogleJavaFormatFormatterFunc, nơi kiểu google-java-format được phân giải, và so sánh reflection của adapter với API JavaFormatterOptions.Style của google-java-format 1.37.0. Tái hiện bằng cấu hình Maven đã được báo cáo và chạy mvn spotless:check; được xem là hoàn tất khi phiên bản 1.37.0 hoàn thành mà không có InvocationTargetException và các tùy chọn kiểu hiện có vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Overriding the google-java-format version to 1.37.0 makes spotless:check fail with InvocationTargetException. Spotless then reports it as google-java-format(java.lang.reflect.InvocationTargetException) and gives no cause.

Environment

  • spotless-maven-plugin 3.10.3 (spotless-lib 4.10.3)
  • google-java-format 1.37.0 (works with 1.36.1)
  • JDK 21 locally, and the same failure on the CI runner

Config

<googleJavaFormat>
  <version>1.37.0</version>
  <reflowLongStrings>true</reflowLongStrings>
  <formatJavadoc>false</formatJavadoc>
</googleJavaFormat>

Cause
Running Maven with -Xlog:exceptions=info showed the wrapped error:

java.lang.NoSuchMethodError: 'JavaFormatterOptions$Style JavaFormatterOptions$Style.valueOf(java.lang.String)'

GoogleJavaFormatFormatterFunc calls JavaFormatterOptions.Style.valueOf(String). In 1.36.1, Style is an enum. In 1.37.0 it is a record (extends java.lang.Record, with a builder() and toBuilder()), and valueOf no longer exists. This looks related to the new --style=google|aosp flag. Style.GOOGLE and Style.AOSP still exist as static fields.

Ruled out

  • The javac --add-exports flags: the 1.37.0 formatter works with them.
  • Guava version: it works with 32.1.3, 33.2.1 and 33.6.0.
  • Missing APIs: Builder.style, formatJavadoc, Formatter(JavaFormatterOptions), RemoveUnusedImports, ImportOrderer.reorderImports(String, Style) and StringWrapper.wrap are all present in 1.37.0.

Repro
Set <version>1.37.0</version> on the googleJavaFormat step, then run mvn spotless:check.

The adapter will need to map the style name to the new Style type, for example with Style.GOOGLE and Style.AOSP, instead of calling valueOf.

Downstream, this is blocking a Renovate bump: bytestreams-io/codec-core#164.

Ngôn ngữ chính
Java
Star
5.7k
Fork
565
Merge trung bình
2 ngày 14 giờ
Pull request đã merge (30 ngày)
66

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của diffplug/spotless

Tất cả issue của diffplug/spotless

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.