`error: expected token: '_'; generated instead`
I am trying 2.58.0 on my project.
I get
Step 'palantir-java-format' found problem in 'src\main\java\org\jabref\gui\commonfxcontrols\CitationKeyPatternsPanel.java':
69:39: error: expected token: '_'; generated instead
com.palantir.javaformat.java.FormatterException: 69:39: error: expected token: '_'; generated instead
at com.palantir.javaformat.java.Formatter.getFormatReplacements(Formatter.java:322)
at com.palantir.javaformat.java.Formatter.formatSource(Formatter.java:297)
at com.palantir.javaformat.java.Formatter.formatSource(Formatter.java:252)
at com.palantir.javaformat.java.Formatter.formatSourceAndFixImports(Formatter.java:269)
at com.palantir.javaformat.java.FormatterServiceImpl.formatSourceReflowStringsAndFixImports(FormatterServiceImpl.java:43)
The code is
this.setOnSort(event ->
viewModel.patternListProperty().sort(CitationKeyPatternsPanelViewModel.defaultOnTopComparator));
patternColumn.setSortable(true);
Variable event is unused, but the error appears at true. When replacing event by _, the error persists.
Full case: https://github.com/JabRef/jabref-koppor/pull/672. Execute ./gradlew spotlessApply on the command line.
Any update on this issue? We're unable to use spotless plugin while people begin to use '_' for unused variables.
+1 on this, I came looking to replace Google formatter and found this did a much better job of formatting but failed with this error in a java 24 app.
Same error for the following code
static <T, R> Gatherer<T, ?, R> map(Function<T, R> f) {
Integrator<Void, T, R> integrator = (_, e, ds) -> {
var ir = f.apply(e);
return ds.push(ir);
};
return Gatherer.of(integrator);
}
Execution failed for task ':shared:spotlessJavaApply'.
> There were 1 lint error(s), they must be fixed or suppressed.
src/.../Gatherers.java:L16 palantir-java-format(palantir-java-format) error: expected token: '_'; generated instead
Resolve these lints or suppress with `suppressLintsFor`
Note that we dropped activities regarding planatir-java-format as prettier-java worked well on our Java 24 code. (We activated experimentalOperatorPosition: start (hint by https://github.com/jhipster/prettier-java/issues/534#issuecomment-3024231994) and tabWidth: 4 in .prettierrc.yaml). (Full case: https://github.com/JabRef/jabref-koppor/pull/717)
I leave the issue open for reference as it still seems to be unsolved.
This issue has been reported in two other tickets, and given by the number of open issues, I don't think anyone cares about this repo anymore. @koppor This blog post discusses the pros and cons of various Java formatters, and Prettier seems to have its own problems including installation and inconsistency between versions.
@koppor This blog post discusses the pros and cons of various Java formatters
Thank you for the link! The poster appears a bit too negative to me.
, and Prettier seems to have its own problems including installation
There is an IntelliJ plugin: https://plugins.jetbrains.com/plugin/10456-prettier
and inconsistency between versions.
I tend to like it. As user, I can choose which style to follow: And old style or an updated one. Updates can be fixes in the parser logic or learnings based on communnity feedback.
Unnamed variables & patterns support was added in https://github.com/palantir/palantir-java-format/pull/1410
Sadly, the problem now shifts to spotless (in my case, the spotless-maven-plugin), which doesn't recognise _ and flags the file to be excluded from formatting.
Darn catch-22's.
@talios, it's strange. I don't see any problem with spotless-maven-plugin/2.44.5 + palantir-java-format/2.74.0.
@chongkai weird, seemed to work fine now - did show up as a warning but worked fine, and I see spotless-maven-plugin 2.3.0 is out as well.
So all good.