openrewrite / openrewrite/rewrite-static-analysis

MissingOverrideAnnotation/Cleanup adds extra space when method return type is annotated

Open
#17 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

Sample code in pgjdbc: https://github.com/pgjdbc/pgjdbc/blob/135be5a4395033a4ba23a1dd70ad76e0bd443a8d/pgjdbc/src/main/java/org/postgresql/util/PSQLWarning.java#L21

import org.checkerframework.checker.nullness.qual.Nullable;
class Sample {
  public @Nullable String getMessage() {
  }
}

Note that @Nullable is type annotation, so it should better be placed near to String rather than "before the method". In other words, @Nullable public ... is incorrect.

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/util/PSQLWarning.java b/pgjdbc/src/main/java/org/postgresql/util/PSQLWarning.java
index 49def9d..f81c905 100644
--- a/pgjdbc/src/main/java/org/postgresql/util/PSQLWarning.java
+++ b/pgjdbc/src/main/java/org/postgresql/util/PSQLWarning.java
@@ -18,7 +18,7 @@ org.openrewrite.java.cleanup.MissingOverrideAnnotation
     this.serverError = err;
   }
 
-  public @Nullable String getMessage() {
+  public  @Nullable String getMessage() {
     return serverError.getMessage();
   }

After ./gradlew rewriteRun, the source becomes (extra whitespace is really added before @Nullable)

  @Override
  public  @Nullable String getMessage() {
    return serverError.getMessage();
  }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the MissingOverrideAnnotation and Cleanup recipes and their tests in this repository. Reproduce the sample with the Gradle rewriteDryRun or rewriteRun configuration shown, then add coverage confirming that placing @Override before a method with a type-use annotation does not introduce an extra space before @Nullable.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.