google-java-format 1.37.0: NoSuchMethodError on JavaFormatterOptions$Style.valueOf (Style is now a record)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- build-system
Research direction
Start at GoogleJavaFormatFormatterFunc, where the google-java-format style is resolved, and compare the adapter's reflection against google-java-format 1.37.0's JavaFormatterOptions.Style API. Reproduce with the reported Maven configuration and run mvn spotless:check; done means version 1.37.0 completes without InvocationTargetException while existing style options still work.
Written by the indexing model from the issue text.
Description
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-exportsflags: 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)andStringWrapper.wrapare 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.
- Dominant language
- Java
- Stars
- 5.7k
- Forks
- 563
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 52
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diffplug/spotless
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
diffplug/spotless#3125 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
All issues in diffplug/spotless
Similar issues
-
1.0.0-rc2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#377 ·
Maintainers usually reply within 1 day
-
area/dependencies backport/26.4 kind/cve severity/high source/scan-dependencies status/triage
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
(primitive-collections-base) Use `NumberInput` to parse numeric map keys, as `jackson-databind` doesOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
FasterXML/jackson-datatypes-collections#270 ·
Maintainers usually reply within 1 day
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day