Demo application to demonstrate an issue using the spring-javaformat checkstyle rules with switch
expressions.
→ spring-io/spring-javaformat#300
The default spring-javaformat checkstyle rules includes the SpringLambdaCheck
which throws the following exception if
the source code contains a switch
expression.
String message = switch (args.length) {
case 0 -> "No arg";
case 1 -> "One arg";
default -> getText.apply(args.length);
};
A full code example could be found in this repository:
- POM:
pom.xml
- Checkstyle config:
checkstyle.xml
- Example Java class:
SampleApplication.java
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.2:check (default-cli) on project spring-javaformat-maven-sample: Failed during checkstyle configuration: Exception was thrown while processing /home/reichardt/Projects/_github/SpringLambdaCheck-with-switch-expression/src/main/java/sample/SampleApplication.java: Cannot invoke "com.puppycrawl.tools.checkstyle.api.DetailAST.getChildCount(int)" because "ast" is null -> [Help 1]
- Clone this repo
- Run
mvn checkstyle:check
→ The error occurs
Exclude the SpringLambdaCheck
, see comment in checkstyle.xml
.