Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#3,126 0 comments 0 reactions 0 assignees View on GitHub

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-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.

Dominant language
Java
Stars
5.7k
Forks
563
Avg merge
1d 8h
Merged PRs (30d)
52

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.