Skip to content

CategoryToTag - ClassCastException on fully-qualified class as category #305

@nmck257

Description

@nmck257

Test case:

    @Test
    void fullyQualifedClass() {
        rewriteRun(
          java(
            """
              package a;
              public interface FastTests {}
              """
          ),
          java(
            """
                  package b;
                  
                  import org.junit.experimental.categories.Category;
                  
                  @Category(a.FastTests.class)
                  public class B {
                  }
              """,
            """
                  package b;
                  
                  import org.junit.jupiter.api.Tag;
                  
                  @Tag("FastTests")
                  public class B {
                  }
              """
          )
        );
    }

yields:

java.lang.AssertionError: Failed to parse sources or run recipe
Caused by: org.openrewrite.internal.RecipeRunException: Exception while visiting project file 'b\B.java (in B)', caused by: 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 'app'), at org.openrewrite.java.testing.junit5.CategoryToTag$CategoryToTagVisitor.lambda$categoryAnnotationToTagAnnotations$0(CategoryToTag.java:115)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions