rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

ChangeType leads to botched imports for nested fields

Open timtebeek opened this issue 1 year ago • 1 comments

After

  • https://github.com/openrewrite/rewrite/pull/4291

We continued to see issues in

  • https://github.com/openrewrite/rewrite-jackson/pull/6

I've updated the test to better replicate the issue there. With this change the test fails with left imports.

Unexpected result in "A.java":
diff --git a/A.java b/A.java
index 98d3bcb..da17811 100644
--- a/A.java
+++ b/A.java
@@ -1,6 +1,8 @@ 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
 
 import static com.fasterxml.jackson.databind.SerializationFeature.WRAP_ROOT_VALUE;
+import static org.codehaus.jackson.map.SerializationConfig.SerializationFeature.WRAP_ROOT_VALUE;
 
 class A {
     void test() {

timtebeek avatar Jun 27 '24 17:06 timtebeek

@sambsnyd if you're up for a puzzle, here's that updated test. I didn't yet get into looking why this now happens

timtebeek avatar Jun 27 '24 17:06 timtebeek

This comparison fails https://github.com/openrewrite/rewrite/blob/f6473b6bab48a652629744c0633b84e20e7df2ce/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java#L272 For this test https://github.com/openrewrite/rewrite/blob/1d8b3c3eb8616a84ecd0de1d44f2feb7f393a1ae/rewrite-java-test/src/test/java/org/openrewrite/java/ChangeTypeTest.java#L164-L166

Because everything up to java. is a J.FieldAccess, all of it ending up in maybeClass, whereas that should only contain the simple class name. image

timtebeek avatar Jul 02 '24 20:07 timtebeek