Open
Description
Java 21 / JEP 441 : Pattern Matching for switch code result in com.palantir.javaformat.java.FormatterException
What happened?
This method compiles using JDK 21:
class Example {
static String test(CharSequence charSequence) {
return switch (charSequence) {
case String s when s.isEmpty() -> "empty string";
case String s -> "non-empty string";
default -> "not a String";
};
}
}
However, when using the spotless-maven-plugin
together with <palantirJavaFormat>
results in an exception:
mvn spotless:apply
[...]
Unable to format file [path to Example.java]: com.palantir.javaformat.java.FormatterException: error: expected token: 'when'; generated - instead -> [Help 1]
Maven config:
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>
<configuration>
<java>
<palantirJavaFormat>
<version>2.38.0</version>
</palantirJavaFormat>
</java>
</configuration>
</plugin>
Maven:
mvn -v
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Java version: 21, vendor: Amazon.com Inc.
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "13.6.1", arch: "x86_64", family: "mac"
What did you want to happen?
The maven-spotless-plugin
and palanter-java-format
should accept or reformat code that is supported by JDK 21
Metadata
Metadata
Assignees
Labels
No labels