palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
409 stars 43 forks source link

java.lang.NoSuchMethodError: 'com.sun.tools.javac.tree.JCTree com.sun.tools.javac.tree.JCTree$JCImport.getQualifiedIdentifier()' #943

Closed lost22git closed 6 months ago

lost22git commented 9 months ago

gradle: 8.4 openjdk: 21 palantir-graddle-plugin: 2.38.0

spotless {
  java {
    target '**/src/main/java/**/*.java', '**/src/test/java/**/*.java'
    palantirJavaFormat()
    removeUnusedImports()
  }

  groovyGradle { // for gradle groovy files
    greclipse() // Uses the formatting rules of Eclipse
  }
}
Step 'palantir-java-format' found problem in 'app/src/main/java/lost/test/quarkus/BaselineController.java':
'com.sun.tools.javac.tree.JCTree com.sun.tools.javac.tree.JCTree$JCImport.getQualifiedIdentifier()'
java.lang.NoSuchMethodError: 'com.sun.tools.javac.tree.JCTree com.sun.tools.javac.tree.JCTree$JCImport.getQualifiedIdentifier()'
        at com.palantir.javaformat.java.RemoveUnusedImports.getSimpleName(RemoveUnusedImports.java:245)
        at com.palantir.javaformat.java.RemoveUnusedImports.buildReplacements(RemoveUnusedImports.java:225)
        at com.palantir.javaformat.java.RemoveUnusedImports.removeUnusedImports(RemoveUnusedImports.java:209)
        at com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc.apply(PalantirJavaFormatFormatterFunc.java:42)
        at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:32)
        at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:82)
        at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:103)
        at com.diffplug.spotless.Formatter.compute(Formatter.java:246)
        at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:203)
        at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:190)
        at com.diffplug.gradle.spotless.SpotlessTaskImpl.processInputFile(SpotlessTaskImpl.java:105)
        at com.diffplug.gradle.spotless.SpotlessTaskImpl.performAction(SpotlessTaskImpl.java:89)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
1chz commented 8 months ago

I have same issue

sebastianjg commented 8 months ago

I had the same error, although with Maven, it went away after I added version in spotless-maven-plugin for <palantirJavaFormat>

dili91 commented 8 months ago

The issue has been fixed on palantir version 2.38.0. I think the only outstanding issue you're facing is that spotless is by default pinning an older version of palantir, based on this open issue.

You can fix this by specifying a custom palantir version in your gradle file - if you don't want to wait for this to be upgraded on spotless:

spotless {
    java {
        palantirJavaFormat("2.38.0")
        removeUnusedImports()
    }
}
lost22git commented 6 months ago

see https://github.com/palantir/palantir-java-format/issues/976