Skip to content

Regression in ChangeType recipe #5066

@BoykoAlex

Description

Consider the following unit test:

    @Test
    void testOkWithTopLevelType1() {
        rewriteRun( //language=java
          spec -> spec.recipe(new ChangeType("java.util.Map$Entry", "java.util.List", true)),
          java("""
               import java.util.Map;

               public class TestController {

                   public Map.Entry respond() {
                      return null;
                   }
               }
               """,
            """
               import java.util.List;

               public class TestController {

                   public List respond() {
                      return null;
                   }
               }
            """)
        );
    }

This test fails because actual results are:

public class TestController {

    public java.util.List respond() {
       return null;
    }
}

New type name appears fully qualified. I've traced this dow to this change

The change in the J class:

        public boolean isFullyQualifiedClassReference(String className) {
            if (getName().getFieldType() == null && getName().getType() instanceof JavaType.FullyQualified &&
                !(getName().getType() instanceof JavaType.Unknown) &&
                TypeUtils.fullyQualifiedNamesAreEqual(((JavaType.FullyQualified) getName().getType()).getFullyQualifiedName(), className)) {
                return true;
            } else if (!className.contains(".")) {
                return false;
            }
            return isFullyQualifiedClassReference(this, TypeUtils.toFullyQualifiedName(className), className.length());
        }

If the first if block is commented out then it works. There is some kind of mistake there it seems... I don't see where this - the field access node content is used there... just its type is used.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtest providedAlready replicated with a unit test, using JUnit pioneer's ExpectedToFail

    Type

    Projects

    • Status

      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions