Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#3,126 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Goooler 已经在做这个了。

开始于 2026年10月3日。

  • #1472 来自 @Goooler —— 未关闭
  • #1477 来自 @copybara-service —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
build-system

调研方向

从解析 google-java-format 样式的 GoogleJavaFormatFormatterFunc 开始,将适配器的反射与 google-java-format 1.37.0 的 JavaFormatterOptions.Style API 进行比较。使用报告中的 Maven 配置复现,并运行 mvn spotless:check;完成标准是 1.37.0 版本在没有 InvocationTargetException 的情况下完成,同时现有样式选项仍能正常工作。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
5.7k
派生
565
平均合并
2 天 15 小时
30 天内合并 PR
65

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

diffplug/spotless 的其他 Issue

查看 diffplug/spotless 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。