You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
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
In this example, the position of the
@Nonnull
annotation shifts from its original location to the location ofString 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.
The text was updated successfully, but these errors were encountered: