Skip to content

Static import of JAX-RS Response.Status.Family causes ClassCastException #852

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 Jul 31, 2023 · 0 comments · Fixed by #853
Closed

Static import of JAX-RS Response.Status.Family causes ClassCastException #852

bottemav opened this issue Jul 31, 2023 · 0 comments · Fixed by #853
Labels
type: bug Something isn't working

Comments

@bottemav
Copy link
Contributor

bottemav commented Jul 31, 2023

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

SBM Version
0.14.1-SNAPSHOT

SBM Application

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. Add import import javax.ws.rs.container.ContainerResponseContext; and import static javax.ws.rs.core.Response.Status.Family.SUCCESSFUL;
  3. Add method
    private boolean isResponseStatusSuccessful(ContainerResponseContext responseContext) {
        return responseContext.getStatusInfo().getFamily() == SUCCESSFUL;
    }
  1. Run MigrateJaxRsAnnotationsRecipeIntegrationTest
  2. See error

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

Stacktrace

java.lang.ClassCastException: class org.openrewrite.java.tree.J$FieldAccess cannot be cast to class org.openrewrite.java.tree.J$Identifier (org.openrewrite.java.tree.J$FieldAccess and org.openrewrite.java.tree.J$Identifier are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @198e2867)
        at org.openrewrite.java.tree.J$FieldAccess.getSimpleName(J.java:1907)
        at org.openrewrite.java.tree.J$Import.getTypeName(J.java:2630)
        at org.openrewrite.java.tree.J$Import.getTypeName(J.java:2581)
        at org.springframework.sbm.java.impl.OpenRewriteImport.getName(OpenRewriteImport.java:28)
        at org.springframework.sbm.java.impl.OpenRewriteImport.matches(OpenRewriteImport.java:33)
        at org.springframework.sbm.java.impl.OpenRewriteJavaSource.lambda$hasImportStartingWith$2(OpenRewriteJavaSource.java:99)
        ...
        at org.springframework.sbm.java.impl.OpenRewriteJavaSource.lambda$hasImportStartingWith$3(OpenRewriteJavaSource.java:99)
        ...
        at org.springframework.sbm.java.impl.OpenRewriteJavaSource.hasImportStartingWith(OpenRewriteJavaSource.java:98)
        at org.springframework.sbm.java.impl.ProjectJavaSourcesImpl.lambda$hasImportStartingWith$0(ProjectJavaSourcesImpl.java:88)
        ...
        at org.springframework.sbm.java.impl.ProjectJavaSourcesImpl.hasImportStartingWith(ProjectJavaSourcesImpl.java:88)
        at org.springframework.sbm.java.migration.conditions.HasImportStartingWith.evaluate(HasImportStartingWith.java:42)
        at org.springframework.sbm.engine.recipe.Recipe.isApplicable(Recipe.java:92)
        at org.springframework.sbm.engine.recipe.Recipes.lambda$getApplicable$2(Recipes.java:50)

Desktop (please complete the following information):

  • OS: Windows
  • Version 11 22H2

Additional context
The issue seems similar to issue #691

@bottemav bottemav added the type: bug Something isn't working label Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant