Skip to content

Incompatible with JDK 21 #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lalib opened this issue Sep 21, 2023 · 10 comments
Open

Incompatible with JDK 21 #934

lalib opened this issue Sep 21, 2023 · 10 comments

Comments

@lalib
Copy link

lalib commented Sep 21, 2023

What happened?

Failed with using Spotless Maven plugin and palantir rule:

[INFO] --- spotless:2.39.0:apply (default-cli) @ X ---
[ERROR] Step 'palantir-java-format' found problem in 'X.java':
253:44: error: expected token: '_'; generated  instead
com.palantir.javaformat.java.FormatterException: 253:44: error: expected token: '_'; generated  instead
    at com.palantir.javaformat.java.Formatter.getFormatReplacements (Formatter.java:302)
    at com.palantir.javaformat.java.Formatter.formatSource (Formatter.java:277)
    at com.palantir.javaformat.java.Formatter.formatSource (Formatter.java:245)
    at com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc.apply (PalantirJavaFormatFormatterFunc.java:43)
    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.spotless.maven.SpotlessApplyMojo.process (SpotlessApplyMojo.java:48)
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:229)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:260)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:172)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:100)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:821)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:270)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
@booniepepper
Copy link

booniepepper commented Oct 13, 2023

Also saw a failure (although a slightly different one) with Spotless and Gradle here: https://github.com/openfga/java-sdk/actions/runs/6510767947/job/17685150920?pr=27

@koppor
Copy link
Contributor

koppor commented Nov 16, 2023

This issue should be refined: When did you encounter this issue? I tried the plugin on Java 21 in a JavaFX project (at JabRef/jabref-koppor#663) - and it worked.

@ollehallin
Copy link

This code fails to format with palantir-java-format 2.39.0:

final var currentOffsets = new HashMap<Integer, Long>();

currentOffsets.computeIfAbsent(partition, _ -> new AtomicLong()).set(consumerRecord.offset());

It generates

com.palantir.javaformat.java.FormatterException: 156:60: error: expected token: '_'; generated instead -> [Help 1]

@koppor
Copy link
Contributor

koppor commented Dec 15, 2023

For the interested readers: Using _ is from JEP-443. Good explanation at https://howtodoinjava.com/java/unnamed-patterns-and-variables/

@jvissers
Copy link

Just a question: are there any known workarounds for this?

@koppor
Copy link
Contributor

koppor commented Mar 4, 2025

Just a question: are there any known workarounds for this?

I thnk, you can try #1211 or #935. You can report in the respective PR whether that version works for you.

@koppor
Copy link
Contributor

koppor commented Mar 13, 2025

partially fixed by #1211 - use release 2.57.0 or later.

@wollefitz
Copy link

wollefitz commented Mar 13, 2025

@koppor I just tried com.diffplug.spotless:spotless-maven-pluginversion 2.44.3 in combination with palantir-java-format version 2.58.0. This still results into the same error as reported above when using unnamed variables:

[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.44.3:apply (spotless-format) on project foo: Unable to format file bar.java: com.palantir.javaformat.java.FormatterException: 57:17: error: expected token: '_'; generated  instead -> [Help 1]

Java version

java --version
openjdk 21.0.6 2025-01-21 LTS
OpenJDK Runtime Environment Temurin-21.0.6+7 (build 21.0.6+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.6+7 (build 21.0.6+7-LTS, mixed mode, sharing)

@koppor
Copy link
Contributor

koppor commented Mar 13, 2025

@koppor I just tried com.diffplug.spotless:spotless-maven-pluginversion 2.44.3 in combination with palantir-java-format version 2.58.0. This still results into the same error as reported above when using unnamed variables:

Thank you for the feedback. I was too happy to see #1211 merged. Let's hope for the best that the other issues will also be addressed.

@koppor
Copy link
Contributor

koppor commented Mar 13, 2025

@wollefitz I think, you need to raise your voice as reaction to #952 (comment) @crogoz seems to be an official maintainer.

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

No branches or pull requests

6 participants