-
Notifications
You must be signed in to change notification settings - Fork 109
Fix Lombok recipes incorrectly replacing getters/setters accessing other objects' fields #873
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…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]>
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]>
mergify bot
added a commit
to robfrank/linklift
that referenced
this pull request
Oct 30, 2025
…19.0 to 3.20.0 [skip ci] [//]: # (dependabot-start)⚠️ \*\*Dependabot is rebasing this PR\*\*⚠️ Rebasing might not happen immediately, so don't worry if this takes some time. Note: if you make any changes to this PR yourself, they will take precedence over the rebase. --- [//]: # (dependabot-end) Bumps [org.openrewrite.recipe:rewrite-migrate-java](https://github.com/openrewrite/rewrite-migrate-java) from 3.19.0 to 3.20.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-migrate-java's releases](https://github.com/openrewrite/rewrite-migrate-java/releases).* > 3.20.0 > ------ > > What's Changed > -------------- > > * Fix Lombok recipes incorrectly replacing getters/setters accessing other objects' fields by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#873](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/873) > * Update suppressions by [`@Laurens-W`](https://github.com/Laurens-W) in [openrewrite/rewrite-migrate-java#874](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/874) > * Fix duplicate [`@Getter`](https://github.com/Getter) annotations on multiple variable declarations by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#877](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/877) > * Enable the switch recipes as part of the Java 21 migration by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#878](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/878) > * Fix `NoGuavaSetsNewHashSet` to skip `Iterable`-only arguments by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#882](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/882) > * Convert Guava `Predicates.and` and `.or` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#885](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/885) > * Convert Guava `Predicates.equalTo` and `.not` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#887](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/887) > * OpenRewrite recipe best practices by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#888](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/888) > > **Full Changelog**: <openrewrite/rewrite-migrate-java@v3.19.0...v3.20.0> Commits * [`ecb6886`](openrewrite/rewrite-migrate-java@ecb6886) OpenRewrite recipe best practices ([#888](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/888)) * [`8014157`](openrewrite/rewrite-migrate-java@8014157) Convert Guava `Predicates.equalTo` and `.not` ([#887](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/887)) * [`cef9c1f`](openrewrite/rewrite-migrate-java@cef9c1f) Convert Guava `Predicates.and` and `.or` ([#885](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/885)) * [`67e8d8c`](openrewrite/rewrite-migrate-java@67e8d8c) Fix `NoGuavaSetsNewHashSet` to skip `Iterable`-only arguments ([#882](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/882)) * [`92f9a94`](openrewrite/rewrite-migrate-java@92f9a94) Enable the switch recipes as part of the Java 21 migration ([#878](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/878)) * [`209211e`](openrewrite/rewrite-migrate-java@209211e) [Auto] SDKMAN! Java candidates as of 2025-10-20T1016 * [`ce56846`](openrewrite/rewrite-migrate-java@ce56846) Fix duplicate [`@Getter`](https://github.com/Getter) annotations on multiple variable declarations ([#877](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/877)) * [`e18534b`](openrewrite/rewrite-migrate-java@e18534b) Add missed recipes to Java 6 and No Guava recipes * [`207d898`](openrewrite/rewrite-migrate-java@207d898) Update suppressions ([#874](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/874)) * [`7ebbf72`](openrewrite/rewrite-migrate-java@7ebbf72) Fix Lombok recipes incorrectly replacing getters/setters accessing other obje... * Additional commits viewable in [compare view](openrewrite/rewrite-migrate-java@v3.19.0...v3.20.0) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue where
UseLombokGetterandUseLombokSetterrecipes were incorrectly replacing getter/setter methods that access fields of other objects.Problem
The recipes were treating expressions like
sample.numberas if they were accessing a field of the current class, when in reality they were accessing a field of another object (sample).Before (incorrect behavior):
Would incorrectly transform to:
Solution
Modified
LombokUtils.isGetter()andLombokUtils.isSetter()to only handlethis.fieldpatterns forJ.FieldAccessexpressions. Now the recipes correctly identify that methods accessing fields of other objects should not be replaced with Lombok annotations.Changes
LombokUtils.isGetter()to check that field access targets are explicitlythisLombokUtils.isSetter()with the same pattern for consistencyTest Plan
noChangeWhenMethodReturnsFieldOfAnotherObject()inUseLombokGetterTestnoChangeWhenMethodSetsFieldOfAnotherObject()inUseLombokSetterTest🤖 Generated with Claude Code