openrewrite / openrewrite/rewrite

Error parsing simple Lombok builder with method variation

Open
#5,299 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug java parser
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What version of OpenRewrite are you using?

I am using

  • org.apache.maven.plugins -> maven-compiler-plugin -> 3.14.0
  • org.openrewrite.maven -> rewrite-maven-plugin v6.6.1
  • org.projectlombok -> lombok -> 1.18.38

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

<dependencies>
  <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.38</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
...
<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>6.6.1</version>
  <configuration>
    <activeRecipes>
      <recipe>org.openrewrite.java.format.TabsAndIndents</recipe>
    </activeRecipes>
</configuration>
</plugin>

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

package org.springframework.samples.petclinic;

import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class TestNewThing {

    String someThing;
    String someOtherThing;
    String failing;

    public static class TestNewThingBuilder{

        public TestNewThingBuilder failing(String failing, String additional) {
                this.failing = failing.concat(additional);
            return this;
        }

        public TestNewThingBuilder failing(String failing) {
                this.failing = failing;
            return this;
        }
    }
}

What did you expect to see?

package org.springframework.samples.petclinic;

import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class TestNewThing {

    String someThing;
    String someOtherThing;
    String failing;

    public static class TestNewThingBuilder{

        public TestNewThingBuilder failing(String failing, String additional) {
            this.failing = failing.concat(additional);
            return this;
        }

        public TestNewThingBuilder failing(String failing) {
            this.failing = failing;
            return this;
        }
    }
}

What did you see instead?

I see no changes to the source file due to error.

What is the full stack trace of any errors you encountered?

[WARNING] There were problems parsing some source files
[WARNING] There were problems parsing src\main\java\org\springframework\samples\petclinic\TestNewThing.java
[WARNING] java.lang.IllegalStateException: src\main\java\org\springframework\samples\petclinic\TestNewThing.java is not print idempotent. 
diff --git a/C:/idea-projects/spring-petclinic-migration/src/main/java/org/springframework/samples/petclinic/TestNewThing.java b/C:/idea-projects/spring-petclinic-migration/src/main/java/org/springframework/samples/petclinic/TestNewThing.java
index 9bf7951..2b93954 100644
--- a/C:/idea-projects/spring-petclinic-migration/src/main/java/org/springframework/samples/petclinic/TestNewThing.java
+++ b/C:/idea-projects/spring-petclinic-migration/src/main/java/org/springframework/samples/petclinic/TestNewThing.java
@@ -14,10 +14,9 @@ 
 
     public static class TestNewThingBuilder{
 
-        public TestNewThingBuilder failing(String failing, String additional) {
+        StringsomeThing TestNewThingBuilder failing(String failing,someOtherThing, String additional) {
                 this.failing = failing.concat(additional);
-            return this;
-        }
+            TestNewThingBuilder  }
 
         public TestNewThingBuilder failing(String failing) {
                 this.failing = failing;

  org.openrewrite.Parser.requirePrintEqualsInput(Parser.java:52)

Are you interested in contributing a fix to OpenRewrite?

I hope so. Just catching up for now.

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

Reproduce the failure with the provided TestNewThing.java example and the TabsAndIndents recipe, then start at Parser.requirePrintEqualsInput(Parser.java:52) from the stack trace. Trace why the overloaded Lombok builder method produces malformed output; done means the source parses and prints idempotently while applying the expected indentation changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.