Skip to content

RemoveUnusedPrivateFields removes lombok annotated field when annotation is after visibility modifier #757

@protocol7

Description

@protocol7

What version of OpenRewrite are you using?

  • org.openrewrite:rewrite-core:8.63.4
  • org.openrewrite.recipe:rewrite-static-analysis:2.19.0

What is the smallest, simplest way to reproduce the problem?

Another corner case from our code base. We've worked around it, but reporting to improve OpenRewrite.

  @Test
  void removingFieldWithLombok() {
    rewriteRun(
            spec -> spec.recipe(new RemoveUnusedPrivateFields()),
            // language=java
            java(
                    """
                     import lombok.Getter;

                     public class OnField {
                       @Getter private String foo;
                     }
                    """),
            // language=java
            java(
                    """
                     import lombok.Getter;

                     public class OnField2 {
                       private @Getter String foo;
                     }
                    """));
  }

The second case here fails due to the placement of the @Getter annotation.

org.opentest4j.AssertionFailedError: [Expected recipe to complete in 0 cycles, but took at least one more cycle. Between the last two executed cycles there were changes to "OnField2.java"]
expected:
  "import lombok.Getter;

  public class OnField2 {
    private @Getter String foo;
  }"
 but was:
  "import lombok.Getter;

  public class OnField2 {
  }"
	at org.openrewrite.test.LargeSourceSetCheckingExpectedCycles.afterCycle(LargeSourceSetCheckingExpectedCycles.java:97)
	at org.openrewrite.RecipeScheduler.runRecipeCycles(RecipeScheduler.java:95)
	at org.openrewrite.RecipeScheduler.scheduleRun(RecipeScheduler.java:41)
	at org.openrewrite.Recipe.run(Recipe.java:442)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:384)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:130)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions