openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.19k stars 329 forks source link

openrewrite fails when type annotations are specified for arrays #2443

Closed vlsi closed 9 months ago

vlsi commented 1 year ago

Sample code in pgjdbc: https://github.com/pgjdbc/pgjdbc/blob/135be5a4395033a4ba23a1dd70ad76e0bd443a8d/pgjdbc/src/main/java/org/postgresql/gss/GSSInputStream.java#L22

import org.checkerframework.checker.nullness.qual.Nullable;
class Sample {
  byte @Nullable [] unencrypted;
}

Gradle configuration:

plugins {
    id("org.openrewrite.rewrite") version "5.32.0"
}

dependencies {
    rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:1.12.1"))
    rewrite("org.openrewrite.recipe:rewrite-java-security:1.19.0")
}

rewrite {
    activeRecipe("org.openrewrite.java.security.JavaSecurityBestPractices")
    activeRecipe("org.openrewrite.java.security.RegularExpressionDenialOfService")
    activeRecipe("org.openrewrite.java.security.ZipSlip")
    activeRecipe("org.openrewrite.java.cleanup.MissingOverrideAnnotation")
    activeRecipe("org.openrewrite.java.cleanup.Cleanup")
    activeRecipe("org.openrewrite.java.cleanup.NoWhitespaceAfter")
}

./gradlew rewriteDryRun output:

diff --git a/pgjdbc/src/main/java/org/postgresql/gss/GSSInputStream.java b/pgjdbc/src/main/java/org/postgresql/gss/GSSInputStream.java
index 518f622..4210016 100644
--- a/pgjdbc/src/main/java/org/postgresql/gss/GSSInputStream.java
+++ b/pgjdbc/src/main/java/org/postgresql/gss/GSSInputStream.java
@@ -19,7 +19,7 @@ org.openrewrite.java.cleanup.NoWhitespaceAfter
   private GSSContext gssContext;
   private MessageProp messageProp;
   private InputStream wrapped;
-  byte @Nullablebyte @Nullable [] unencrypted;
+  byte @Nullablebyte[] unencrypted;
   int unencryptedPos;
   int unencryptedLength;

After ./gradlew rewriteRun, the source becomes

byte @Nullablebyte[] unencrypted;
tkvangorder commented 1 year ago

@vlsi Which recipe were you running when you encountered this issue?

tkvangorder commented 1 year ago

This appears to be a duplicate of #2490

vlsi commented 1 year ago

I'm inclined #2490 is a variation of this as 2443 < 2490

knutwannheden commented 9 months ago

This has now been fixed by #3848.