google/google-java-format

Error processing case statements using JVM "17-ea (Azul Systems, Inc. 17-ea+12)"

ckmcd opened this issue · 2 comments

It works as expected with 17 (Oracle Corporation 17+35-2724)
It fails as follows with 17-ea (Azul Systems, Inc. 17-ea+12)

 Step 'google-java-format' found problem in 'src/test/java/jdbc/jdbc/MSSQLTestService.java':
195:8: error: java.lang.NoSuchMethodError: 'java.util.List com.sun.source.tree.CaseTree.getLabels()'
        at com.google.googlejavaformat.java.java17.Java17InputAstVisitor.visitCase(Java17InputAstVisitor.java:227)
        at com.google.googlejavaformat.java.java17.Java17InputAstVisitor.visitCase(Java17InputAstVisitor.java:51)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCase.accept(JCTree.java:1317)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
        at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:357)
        at com.google.googlejavaformat.java.JavaInputAstVisitor.visitSwitch(JavaInputAstVisitor.java:1914)
        at com.google.googlejavaformat.java.JavaInputAstVisitor.visitSwitch(JavaInputAstVisitor.java:1895)
        at com.google.googlejavaformat.java.JavaInputAstVisitor.visitSwitch(JavaInputAstVisitor.java:167)

./gradlew --version

 ------------------------------------------------------------
Gradle 8.2
------------------------------------------------------------

Build time:   2023-06-30 18:02:30 UTC
Revision:     5f4a070a62a31a17438ac998c2b849f4f6892877

Kotlin:       1.8.20
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17-ea (Azul Systems, Inc. 17-ea+12)
OS:           Mac OS X 11.3 x86_64

gradle spotless plugin config

        // Apply a specific flavor of google-java-format
        // this matches what was used by spotify.fmt-maven-plugin 2.20
        googleJavaFormat("1.22.0").reflowLongStrings().skipJavadocFormatting()
        indentWithSpaces(2)

        // Ensure every file has the following copyright header.
        licenseHeader("/* ___ (C)\$YEAR */")
    }

Does it reproduce with the latest version of the CLI? Can you share a self-contained example of the Java code that you're seeing this error for?

17-ea (Azul Systems, Inc. 17-ea+12)

I recommend using a released version of JDK 17 (or newer) instead of a JDK 17 early access build.