Skip to content

Static import of JAX-RS MediaType causes ClassCastException #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bottemav opened this issue Jan 3, 2023 · 1 comment · Fixed by #755
Closed

Static import of JAX-RS MediaType causes ClassCastException #691

bottemav opened this issue Jan 3, 2023 · 1 comment · Fixed by #755
Labels
JEE/JAX-RS type: bug Something isn't working

Comments

@bottemav
Copy link
Contributor

bottemav commented Jan 3, 2023

Describe the bug
If a Java class contains a static import for javax.ws.rs.core.MediaType.APPLICATION_JSON then applying the recipe 'migrate-jax-rs' fails with ClassCastException

To Reproduce
Steps to reproduce the behavior:

  1. Go to PersonController (src/test/resources/testcode/bootify-jaxrs/src/main/java/com/example/jee/app/PersonController.java in module spring-shell)
  2. Replace @Consumes(MediaType.APPLICATION_JSON) on line 22 by a static import
  3. Run MigrateJaxRsAnnotationsRecipeIntegrationTest
  4. See error

Expected behavior
The JAX-RS classes are migrated and the integration test succeeds.

Stacktrace

ERROR o.s.s.o.RewriteExecutionContext - org.springframework.sbm.java.refactoring.JavaGlobalRefactoringImpl: Exception occured!
org.openrewrite.UncaughtVisitorException: java.lang.ClassCastException: class org.openrewrite.java.tree.J$Identifier cannot be cast to class org.openrewrite.java.tree.J$FieldAccess (org.openrewrite.java.tree.J$Identifier and org.openrewrite.java.tree.J$FieldAccess are in unnamed module of loader 'app')
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:253)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:240)
	at org.openrewrite.RecipeScheduler.lambda$scheduleVisit$5(RecipeScheduler.java:241)
	at org.openrewrite.RecipeScheduler.lambda$mapAsync$0(RecipeScheduler.java:49)
	at org.openrewrite.scheduling.ForkJoinScheduler.lambda$schedule$0(ForkJoinScheduler.java:41)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1375)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.ClassCastException: class org.openrewrite.java.tree.J$Identifier cannot be cast to class org.openrewrite.java.tree.J$FieldAccess (org.openrewrite.java.tree.J$Identifier and org.openrewrite.java.tree.J$FieldAccess are in unnamed module of loader 'app')
	at org.openrewrite.java.tree.J$Import.getTypeName(J.java:2438)
	at org.openrewrite.java.RemoveImport.lambda$visitCompilationUnit$1(RemoveImport.java:118)
	at org.openrewrite.internal.ListUtils.lambda$flatMap$1(ListUtils.java:199)
	at org.openrewrite.internal.ListUtils.flatMap(ListUtils.java:153)
	at org.openrewrite.internal.ListUtils.flatMap(ListUtils.java:199)
	at org.openrewrite.java.RemoveImport.visitCompilationUnit(RemoveImport.java:112)
	at org.openrewrite.java.RemoveImport.visitCompilationUnit(RemoveImport.java:32)
	at org.openrewrite.java.JavaVisitor.visitJavaSourceFile(JavaVisitor.java:454)
	at org.openrewrite.java.JavaIsoVisitor.visitJavaSourceFile(JavaIsoVisitor.java:39)
	at org.openrewrite.java.JavaIsoVisitor.visitJavaSourceFile(JavaIsoVisitor.java:31)
	at org.openrewrite.java.tree.J$CompilationUnit.acceptJava(J.java:1351)
	at org.openrewrite.java.tree.J.accept(J.java:60)
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:206)
	... 10 common frames omitted

Desktop (please complete the following information):

  • OS: Windows
  • Version 11 22H2
@fabapp2
Copy link
Contributor

fabapp2 commented Jan 3, 2023

Hi @bottemav
thank you for reporting 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JEE/JAX-RS type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants