-
Notifications
You must be signed in to change notification settings - Fork 109
Fix duplicate @Getter annotations on multiple variable declarations #877
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
When multiple variables are declared on one line (e.g., `int foo, bar = 9;`) with corresponding getter methods, the recipe was adding @Getter twice to the same field declaration. This happened because each getter method triggered a separate FieldAnnotator visitor, and both attempted to annotate the shared VariableDeclarations node. The fix adds a check to prevent duplicate annotations by verifying if the annotation already exists before applying it. Fixes #876 🤖 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
@Getterannotation was being added twice to field declarations containing multiple variablesmultipleVariableDeclarationsto verify the fixProblem
When a class had multiple variables declared on one line (e.g.,
int foo, bar = 9;) with corresponding getter methods for each variable, theUseLombokGetterrecipe was incorrectly adding the@Getterannotation twice to the same field declaration.This happened because:
getFoo()andgetBar()) triggered a separateFieldAnnotatorvisitorVariableDeclarationsnode (since both variables share the same declaration)Solution
Updated
FieldAnnotator.visitVariableDeclarations()to check if the annotation already exists before applying it. The fix:Test plan
Test
multipleVariableDeclarationspassesAll tests in
UseLombokGetterTestpassAll tests in
UseLombokSetterTestpassAll Lombok-related tests pass
Fixes Support lombok getter/setter generation for multiple variables declared on a single line #876
🤖 Generated with Claude Code