Skip to content

UnnecessarySemicolon: ignore generated members - #6445

Open
ihabyehia-dev wants to merge 3 commits into
google:masterfrom
ihabyehia-dev:fix/6233-lombok-generated-members
Open

ihabyehia-dev wants to merge 3 commits into
google:masterfrom
ihabyehia-dev:fix/6233-lombok-generated-members

Conversation

@ihabyehia-dev

@ihabyehia-dev ihabyehia-dev commented Dec 2, 2026 •

Copy link
Copy Markdown

Fixes #6233

What changed

Filter class members with no explicit source or with an injected @Generated annotation before scanning for redundant semicolons. A declaration with @Generated written in the source still marks a boundary for the scan. The scan stops at the first token other than a semicolon.

Why

Lombok-generated getters and setters borrow source positions from fields and annotations. Treating those offsets as declaration boundaries can delete required semicolons or miss redundant ones. The revised scan preserves enum separators and handles extra semicolons between fields and at the end of a class.

Testing

  • mvn -pl core -am -Dtest=UnnecessarySemicolonTest -Dsurefire.failIfNoSpecifiedTests=false test passed all 18 focused tests on JDK 25.
  • All 18 focused tests also passed in a local JDK 21 run.
  • The new regression test exercises source-written @Generated fields in a class with Lombok-generated getters. It fails on the previous commit.

} else {
Tree next = tree.getMembers().get(i + 1);
if (!hasExplicitSource(next, state)) {
if (!hasExplicitSource(next, state) || isGenerated(next)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Lombok appends generated accessors after the last explicit field, next is generated and this continue skips scanning the trailing gap to state.getEndPosition(tree) (so an actual extra ; after second won't be caught). Same thing if a generated member sits between two explicit members. Pre-filtering tree.getMembers() to explicit non-generated members before the loop handles both cases while keeping the enum-constant checks intact.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to review my contribution and for your valuable feedback.

I've updated the implementation to follow your suggestion, filtering explicit, non-generated members before iteration while preserving the enum-constant checks.

I've also added regression tests covering both scenarios you mentioned. All 17 targeted tests and the full Maven test suite passed locally.

I hope the revised implementation addresses your concerns. I'd be happy to make any further improvements if needed.

Thank you again for your time and guidance!

ihabyehia-dev and others added 2 commits December 2, 2026 19:16
Keep declarations with source-written @generated annotations in the scan while excluding Lombok-injected members. Cover redundant semicolons between annotated fields and at the end of a class.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnnecessarySemicolon: false positive and code-breaking fix on the fields of a class with Lombok @Getter/@Setter

2 participants