Skip to content
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

MissingOverrideAnnotation changes method return type when it is an annotated array #3877

Closed
vlsi opened this issue Jan 1, 2024 · 2 comments · Fixed by #3860
Closed

MissingOverrideAnnotation changes method return type when it is an annotated array #3877

vlsi opened this issue Jan 1, 2024 · 2 comments · Fixed by #3860
Assignees
Labels
bug Something isn't working

Comments

@vlsi
Copy link

vlsi commented Jan 1, 2024

What version of OpenRewrite are you using?

The issue reproduces with the current snapshot.

MissingOverrideAnnotation converts 2d array to 1d one, so it breaks the code.

Here's a test for the current rewrite-static-analysis:

--- a/src/test/java/org/openrewrite/staticanalysis/MissingOverrideAnnotationTest.java
+++ b/src/test/java/org/openrewrite/staticanalysis/MissingOverrideAnnotationTest.java
@@ -18,6 +18,8 @@ package org.openrewrite.staticanalysis;
 import org.intellij.lang.annotations.Language;
 import org.junit.jupiter.api.Test;
 import org.openrewrite.DocumentExample;
+import org.openrewrite.java.RemoveObjectsIsNull;
+import org.openrewrite.test.AdHocRecipe;
 import org.openrewrite.test.RecipeSpec;
 import org.openrewrite.test.RewriteTest;

@@ -61,10 +63,18 @@ class MissingOverrideAnnotationTest implements RewriteTest {
     @Language("java")
     String testParentParent = """
       package com.example;
-
+      import java.lang.annotation.*;
+
+      @Target({ElementType.TYPE_USE})
+      @interface Nullable {
+      }
+
       class TestParentParent {
           public void testParentParent() {
           }
+
+          public byte @Nullable [][] get2dArray() {
+          }
       }
       """;

@@ -125,6 +135,40 @@ class MissingOverrideAnnotationTest implements RewriteTest {
         );
     }

+    @Test
+    void whenAMethodOverridesFromAParentArray() {
+        rewriteRun(
+          //language=java
+          java(testParentParent),
+          //language=java
+          java(
+            """
+              package com.example;
+
+              class Test extends TestParentParent {
+                  public byte @Nullable [][] get2dArray() {
+                  }
+
+                  public void localMethod() {
+                  }
+              }
+              """,
+            """
+              package com.example;
+
+              class Test extends TestParentParent {
+                  @Override
+                  public byte @Nullable [][] get2dArray() {
+                  }
+
+                  public void localMethod() {
+                  }
+              }
+              """
+          )
+        );
+    }
+

Here's the output:

Unexpected result in "com/example/Test.java":
diff --git a/com/example/Test.java b/com/example/Test.java
index e977a3c..59fa0ca 100644
--- a/com/example/Test.java
+++ b/com/example/Test.java
@@ -2,7 +2,7 @@ 
 
 class Test extends TestParentParent {
     @Override
-    public byte @Nullable [][] get2dArray() {
+    public byte @Nullable [] get2dArray() {
     }
 
     public void localMethod() {
] 
expected: 
  "package com.example;
  
  class Test extends TestParentParent {
      @Override
      public byte @Nullable [][] get2dArray() {
      }
  
      public void localMethod() {
      }
  }"
@vlsi vlsi added the bug Something isn't working label Jan 1, 2024
@timtebeek
Copy link
Contributor

We have a PR in progress that might affect this too:

@traceyyoshima traceyyoshima self-assigned this Jan 2, 2024
@traceyyoshima traceyyoshima transferred this issue from openrewrite/rewrite-static-analysis Jan 2, 2024
@traceyyoshima
Copy link
Contributor

We have a PR in progress that might affect this too:

Confirmed: this issue will be fixed by #3860

@traceyyoshima traceyyoshima moved this from In Progress to Ready to Review in OpenRewrite Jan 2, 2024
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants