Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented May 22, 2025

Before this PR

The build fails with the following error when running on JDK 25

[INFO] --- spotless:2.44.4:apply (default) @ jline-native ---
[INFO] Index file corresponds to a different configuration of the plugin. Either the plugin version or its configuration has changed. Fallback to an empty index
[ERROR] Step 'palantir-java-format' found problem in 'JLineNativeLoaderTest.java':
'java.util.Queue com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics()'
java.lang.NoSuchMethodError: 'java.util.Queue com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics()'
    at com.palantir.javaformat.java.JavaInput.buildToks(JavaInput.java:368)
    at com.palantir.javaformat.java.ImportOrderer.reorderImports(ImportOrderer.java:49)
    at com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc.apply(PalantirJavaFormatFormatterFunc.java:53)
    at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)
    at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
    at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
    at com.diffplug.spotless.Formatter.compute(Formatter.java:135)
    at com.diffplug.spotless.generic.FenceStep$BaseFormatter.applyWithFile(FenceStep.java:229)
    at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:174)
    at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
    at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:97)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:82)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:77)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:73)
    at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:255)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:146)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:339)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:310)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:214)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:179)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:168)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:165)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:110)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:60)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleStarter.execute(DefaultLifecycleStarter.java:123)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:311)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:225)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:149)
    at org.apache.maven.cling.invoker.mvn.MavenInvoker.doExecute(MavenInvoker.java:462)
    at org.apache.maven.cling.invoker.mvn.MavenInvoker.execute(MavenInvoker.java:100)
    at org.apache.maven.cling.invoker.mvn.MavenInvoker.execute(MavenInvoker.java:81)
    at org.apache.maven.cling.invoker.LookupInvoker.doInvoke(LookupInvoker.java:165)
    at org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:135)
    at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:76)
    at org.apache.maven.cling.MavenCling.main(MavenCling.java:51)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke(Method.java:565)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
[ERROR] Step 'toggle' found problem in 'JLineNativeLoaderTest.java':
'java.util.Queue com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics()'
java.lang.NoSuchMethodError: 'java.util.Queue com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics()'
    at com.palantir.javaformat.java.JavaInput.buildToks(JavaInput.java:368)
    at com.palantir.javaformat.java.ImportOrderer.reorderImports(ImportOrderer.java:49)
    at com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc.apply(PalantirJavaFormatFormatterFunc.java:53)
    at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)
    at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
    at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
    at com.diffplug.spotless.Formatter.compute(Formatter.java:135)
    at com.diffplug.spotless.generic.FenceStep$BaseFormatter.applyWithFile(FenceStep.java:229)
    at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:174)
    at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
    at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:97)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:82)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:77)
    at com.diffplug.spotless.DirtyState.of(DirtyState.java:73)
    at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:255)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:146)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:339)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:310)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:214)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:179)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:168)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:165)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:110)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:60)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleStarter.execute(DefaultLifecycleStarter.java:123)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:311)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:225)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:149)
    at org.apache.maven.cling.invoker.mvn.MavenInvoker.doExecute(MavenInvoker.java:462)
    at org.apache.maven.cling.invoker.mvn.MavenInvoker.execute(MavenInvoker.java:100)
    at org.apache.maven.cling.invoker.mvn.MavenInvoker.execute(MavenInvoker.java:81)
    at org.apache.maven.cling.invoker.LookupInvoker.doInvoke(LookupInvoker.java:165)
    at org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:135)
    at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:76)
    at org.apache.maven.cling.MavenCling.main(MavenCling.java:51)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke(Method.java:565)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)

After this PR

The build works correctly

Possible downsides?

The commit uses reflection to call the correct method, but this is the only way to support the incompatible API change introduced in JDK 25 while still supporting older JDK.

@gnodet
Copy link
Contributor Author

gnodet commented May 28, 2025

@crogoz @felixdesouza @CRogers @FinlayRJW anything I can help you with ?

@slachiewicz
Copy link

@gnodet similar fix was also in google-java-format

@gnodet
Copy link
Contributor Author

gnodet commented Jun 6, 2025

@gnodet similar fix was also in google-java-format

Ah, didn't check that one. Both should be fixed I suppose.

@slachiewicz
Copy link

They fixed it with a static variable, that may perform better

@gnodet
Copy link
Contributor Author

gnodet commented Jun 8, 2025

The problem here is more that the team is not responsive at all...
I'm happy to change it to whatever is needed, but if the PR is not applied...

Comment on lines 484 to 488
try {
// Fall back to pre-JDK 25 method (Queue<JCDiagnostic>)
Method queueMethod = DeferredDiagnosticHandler.class.getMethod("getDiagnostics");
return (Collection<JCDiagnostic>) queueMethod.invoke(handler);
} catch (Exception e2) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this particular change does anything? There is no difference between this and lines 480-482. It makes more sense to do the same/equivalent change as google-java-format: https://github.com/google/google-java-format/pull/1247/files.

Copy link
Contributor Author

@gnodet gnodet Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixdesouza You're right, I removed the second fallback which is completely useless.
I also cached the method handle in a static final field to get closer to google/google-java-format#1247. Just cherry-picking their commit could work too I suppose.

@talios
Copy link

talios commented Jul 16, 2025

Any chance of seeing this merged/released soon? I'm starting to test our builds under J25ea and this was the first thing I hit.

@CRogers
Copy link
Contributor

CRogers commented Jul 16, 2025

I've made another PR to apply this change at #1367 - just because some our changelog infra doesn't work well on forks (there's a fix in the works for it but not ready yet)

@CRogers CRogers closed this Jul 16, 2025
@CRogers
Copy link
Contributor

CRogers commented Jul 16, 2025

Released as 2.71.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants