Open fprochazka opened 6 months ago
I think the issue is that OpenRewrite does not yet fully support Java's pattern matching for switch expressions and statements as previewed starting with Java 17 and then released with Java 21. This needs to be fixed in the parser (and printer).
@timtebeek did this one fall through the cracks? I stumbled upon an old Quarkus issue complaining about it and this is a pattern that becomes more and more common.
In our case, the example was:
return switch(rand) {
- case String s -> s;
- case Object o -> String.valueOf(o);
+ defaultcase String s -> s;
+ defaultcase Object o -> String.valueOf(o);
};
hi @gsmet Thanks for the tag! Indeed we haven't yet built in support for switch expressions into our Java 21 parser. Definitely should though; especially as we're eyeing a Java 21 upgrade internally too, which will make us feel this pain too.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a multi-module project
```xmlpom.xml
```yml --- type: specs.openrewrite.org/v1beta/recipe name: com.shipmonk.Cleanup recipeList: - org.openrewrite.java.OrderImports: removeUnused: false - org.openrewrite.java.RemoveObjectsIsNull: { } - org.openrewrite.java.format.OperatorWrap: { } - org.openrewrite.java.format.TypecastParenPad: { } - org.openrewrite.java.format.BlankLines: { } - org.openrewrite.java.format.EmptyNewlineAtEndOfFile: { } - org.openrewrite.java.format.SingleLineComments: { } - org.openrewrite.java.logging.slf4j.LoggersNamedForEnclosingClass: { } - org.openrewrite.java.logging.slf4j.Slf4jLogShouldBeConstant: { } - org.openrewrite.staticanalysis.DefaultComesLast: { } - org.openrewrite.staticanalysis.ModifierOrder: { } - org.openrewrite.staticanalysis.StringLiteralEquality: { } - org.openrewrite.staticanalysis.CompareEnumsWithEqualityOperator: { } - org.openrewrite.staticanalysis.EqualsAvoidsNull: { } - com.shipmonk.tooling.openrewrite.cleanup.ThrowsFormattingRecipe: { } - com.shipmonk.tooling.openrewrite.cleanup.MethodDeclarationParametersWrappingRecipe: { } --- type: specs.openrewrite.org/v1beta/style name: com.shipmonk.Style styleConfigs: - org.openrewrite.java.style.ImportLayoutStyle: classCountToUseStarImport: 9999 nameCountToUseStarImport: 9999 layout: - import all other imports -rewrite.yml
(The problem persists even if I disable my own recipes)
What is the full stack trace of any errors you encountered?
It doesn't like some of the switch statements, but only some and I don't see why. I was able to obtain these details by adding
--errors
to the mvn command