RemoveTryCatchFailBlocks triggers a Java Template parse failure
What version of OpenRewrite are you using?
I am using rewrite-maven-plugin:5.42.0 /
- OpenRewrite v8.45.1
- Maven plugin 5.42.0
- rewrite-testing-frameworks v3.2.0
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a multi module project.
https://github.com/operaton/operaton/tree/v1.0.0-beta-3
Execution is
# build the project once before without testing
./mvnw verify -DskipTests -Dskip.frontend.build=true
# perform recipe on the 'engine' module
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.assertj.JUnitToAssertj -Drewrite.exportDatatables=true -f engine
What is the smallest, simplest way to reproduce the problem?
https://github.com/operaton/operaton/blob/v1.0.0-beta-3/engine/src/test/java/org/operaton/bpm/engine/test/bpmn/mail/EmailSendTaskTest.java
What is the full stack trace of any errors you encountered?
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.42.0:run failed: Error while visiting engine/src/test/java/org/operaton/bpm/engine/test/bpmn/mail/EmailServiceTaskTest.java: java.lang.IllegalArgumentException: Could not parse as Java
org.openrewrite.java.internal.template.JavaTemplateParser.lambda$compileTemplate$13(JavaTemplateParser.java:264)
java.base/java.util.Optional.orElseThrow(Optional.java:403)
org.openrewrite.java.internal.template.JavaTemplateParser.compileTemplate(JavaTemplateParser.java:264)
org.openrewrite.java.internal.template.JavaTemplateParser.lambda$parseBlockStatements$9(JavaTemplateParser.java:176)
org.openrewrite.java.internal.template.JavaTemplateParser.cacheIfContextFree(JavaTemplateParser.java:290)
org.openrewrite.java.internal.template.JavaTemplateParser.parseBlockStatements(JavaTemplateParser.java:171)
org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.maybeReplaceStatement(JavaTemplateJavaExtension.java:451)
org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitStatement(JavaTemplateJavaExtension.java:445)
org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitStatement(JavaTemplateJavaExtension.java:55)
org.openrewrite.java.JavaVisitor.visitTry(JavaVisitor.java:1188)
org.openrewrite.java.tree.J$Try.acceptJava(J.java:5294)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:248)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:150)
org.openrewrite.java.JavaTemplate.apply(JavaTemplate.java:115)
org.openrewrite.java.testing.junit5.RemoveTryCatchFailBlocks$RemoveTryCatchBlocksFromUnitsTestsVisitor.replaceWithAssertDoesNotThrowWithoutStringExpression(RemoveTryCatchFailBlocks.java:137)
...
I haven't been able to reproduce when running RemoveTryCatchFailBlocks, but what stands out is that the only try ... catch in this Java file is this line:
https://github.com/operaton/operaton/blob/v1.0.0-beta-3/engine/src/test/java/org/operaton/bpm/engine/test/bpmn/mail/EmailSendTaskTest.java#L190
And the only thing special there I can see is the | syntax for catching two exception classes (catch (MessagingException | IOException e)).
What the exception here says is that what couldn't be parsed was the Java template code, not the source file itself. So this is either a bug in the recipe or possibly the template engine itself.