Commit 7ebbf72
Fix Lombok recipes incorrectly replacing getters/setters accessing other objects' fields (#873)
* Fix UseLombokGetter incorrectly replacing getters that access fields of other objects
Fixes #872
The UseLombokGetter recipe was incorrectly removing getter methods when
the method body referenced a field of another object (e.g.,
`return sample.number;` where `sample` is a field of the current class).
The issue was in LombokUtils.isGetter() when handling J.FieldAccess
expressions. Previously, it checked if the target object was a field of
the current class, then incorrectly assumed the accessed field should
be annotated with @Getter.
The fix ensures that only `this.field` patterns are handled for
J.FieldAccess expressions, preventing the recipe from replacing getters
that access fields of other objects.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Apply same fix to UseLombokSetter for consistency
The setter logic had the same issue as the getter - it was incorrectly
replacing setter methods when they set fields of other objects
(e.g., `sample.number = value;`).
Applied the same fix: only handle `this.field` patterns for J.FieldAccess
expressions in the isSetter() method.
Added test case to verify the fix.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>1 parent e83ed0d commit 7ebbf72
File tree
3 files changed
+68
-13
lines changed- src
- main/java/org/openrewrite/java/migrate/lombok
- test/java/org/openrewrite/java/migrate/lombok
3 files changed
+68
-13
lines changedLines changed: 18 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
82 | 87 | | |
83 | | - | |
84 | | - | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
181 | 186 | | |
182 | 187 | | |
183 | 188 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
616 | 641 | | |
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
622 | 622 | | |
623 | 623 | | |
624 | 624 | | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
625 | 650 | | |
0 commit comments