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

[BUG] Lombok Annotation Processor incorrectly alters AST node positions for original code #3799

Open
amishra-u opened this issue Dec 18, 2024 · 2 comments · May be fixed by #3800
Open

[BUG] Lombok Annotation Processor incorrectly alters AST node positions for original code #3799

amishra-u opened this issue Dec 18, 2024 · 2 comments · May be fixed by #3800
Assignees
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug javac

Comments

@amishra-u
Copy link

Describe the bug
Lombok, when copying annotations from fields to their corresponding accessor methods, does not perform a deep clone of these annotations. As a result, it alters the position of nodes in the original AST. Any tool relying on the accuracy of node positions in the AST may fail. For example, OpenRewrite, a large-scale code refactoring tool that depends on precise node positioning, encountered issues while processing Lombok-annotated code due to discrepancies between the source file and AST node positions.

For more details, please see this comment:
openrewrite/rewrite#4781 (comment)

To Reproduce

import lombok.Getter;
import lombok.Nonnull;

@Getter
public class Foo {
  @Nonnull private final String foo;
}

In this example, the position of the @Nonnull annotation shifts from its original location to the location of String foo. When Lombok generates the getter method and copies the @nonnull annotation, it erroneously updates the positions of the original @nonnull node due to a shallow copy operation.

Expected behavior
Lombok’s annotation processor should avoid altering the AST node positions of original code.

@amishra-u amishra-u changed the title [BUG] Lombok Annotation Processor Incorrectly Alters AST Node Positions for Original Code [BUG] Lombok Annotation Processor incorrectly alters AST node positions for original code Dec 18, 2024
@Rawi01 Rawi01 added bug javac accepted The issue/enhancement is valid, sensible, and explained in sufficient detail labels Dec 23, 2024
@Rawi01
Copy link
Collaborator

Rawi01 commented Dec 23, 2024

@amishra-u Assigned the issue to you because I noticed that you started to work on it

@timtebeek
Copy link

timtebeek commented Dec 23, 2024

Linking the branch that saw changes here for others interested: master...amishra-u:lombok:ast-pos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug javac
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants