GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Fix #6731: Support lombok.Builder (fix UnnecessaryFullyQualifiedName false positive) by markjoin123 · Pull Request #7198 · pmd/pmd

Conversation

@markjoin123

@markjoin123 markjoin123 commented Oct 19, 2026 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Describe the PR

UnnecessaryFullyQualifiedName reports @lombok.Builder and @lombok.Builder.Default when lombok.Builder is already in scope. That is wrong when builderClassName is "Builder": Lombok generates a nested class of that name, so the simple name Builder no longer refers to the annotation. Since Lombok 1.18.48, @Builder(builderClassName = "Builder") is a compile error and the fully qualified annotation is required. The same clash makes @lombok.Builder.Default necessary inside the type.

Other builder class names are still reported.

This PR adds support for Lombok's Builder annotation.

Related issues

  • Fixes [java] UnnecessaryFullyQualifiedName: False positive for lombok.Builder annotation #6731

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
oowekyala
oowekyala requested changes Oct 23, 2026
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ain/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryFullyQualifiedNameRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@cursor
cursor Bot force-pushed the cursor/fix-ufqn-lombok-builder-7c90 branch from 14047df to da2e150 Compare October 26, 2026 02:02
@markjoin123

markjoin123 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @oowekyala, that makes sense. I reworked the PR accordingly:

  • The special case in UnnecessaryFullyQualifiedNameRule is gone; the rule itself is unchanged.
  • @Builder (on the type, or on a constructor/method) now adds a static nested class symbol to the enclosing AstClassSym, like the other Lombok-generated members from [java] Better Lombok support #3119. The name is <TypeName>Builder by default, or builderClassName when set (* is replaced by the type name). Nothing is added if a nested class with that name already exists.
  • The generated class is visible in the type body and in the scope of the type's own annotations, so @lombok.Builder is no longer reported as an unnecessary qualification when the generated class is named Builder.

Tests: the #6731 cases in UnnecessaryFullyQualifiedName.xml still cover the false positive, and LombokTest now checks the symbol directly (default name, *Builder, constructor and method builders, an existing nested class, Lombok support disabled). UnnecessaryFullyQualifiedNameTest, LombokTest, SymbolTableResolverTest, AstSymbolTests and AstSymbolResolverTest all pass, and checkstyle is clean. The branch is rebased onto current main.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel requested changes Nov 6, 2026
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the PR!

I think we should address the following points (see also the individual comments):

  • Add a comment in SymbolTableResolver explaining why the generated builder class is added to the scope of the class's own annotations. Java scoping doesn't do this; the reason is a Lombok restriction. Since Lombok 1.18.48, @Builder(builderClassName = "Builder") must be written as @lombok.Builder. Also consider moving this block into a separate private method (e.g. addBuildersToAnnotationScope), so that desugarLombokMembers stays easy to read.
  • Fix the generated builder class name for @Builder on methods. Lombok names it after the method's return type, not the enclosing type (e.g. Bar$FooBuilder for static Foo create() in Bar). Please add a test for this.
  • Update the release notes: please remove the "New and Changed Rules" section. This is a bug fix, so the entry under "Fixed Issues" is enough.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/ast/AstClassSym.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/ast/AstClassSym.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .../src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/SymbolTableResolver.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/ast/AstClassSym.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/LombokTest.kt Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel mentioned this pull request Nov 6, 2026
[java] Better Lombok support #3119
Open
@adangel adangel changed the title [java] Fix #6731: UnnecessaryFullyQualifiedName false positive for lombok Builder [java] Fix #6731: Support lombok.Builder (fix UnnecessaryFullyQualifiedName false positive) Nov 6, 2026
@adangel adangel added the needs:user-input Maintainers are waiting for feedback from author label Nov 6, 2026
@cursor
cursor Bot force-pushed the cursor/fix-ufqn-lombok-builder-7c90 branch 2 times, most recently from fdec473 to e0760e4 Compare November 10, 2026 01:21
markjoin123 added 2 commits November 12, 2026 00:02
@markjoin123
[java] Fix pmd#6731: model Lombok @builder as a member class symbol
8933f6d
UnnecessaryFullyQualifiedName reported lombok.Builder when the generated
builder class was named Builder. Add that static nested class to the
enclosing type's symbol, as with other Lombok members, instead of
special-casing the rule. The default name is <TypeName>Builder; builderClassName
overrides it, and an existing nested class of that name is kept.

Fixes pmd#6731
@markjoin123
[java] Fix pmd#6731: name Lombok method builders after the return type
6a3fe12
Address review feedback. Explain the Lombok annotation-scope restriction,
return the synthetic builder classes that were added, and name @builder
on a method after its return type (Desk$BookBuilder for static Book book()).
@cursor
cursor Bot force-pushed the cursor/fix-ufqn-lombok-builder-7c90 branch from e0760e4 to 6a3fe12 Compare November 12, 2026 00:07
@adangel adangel removed the needs:user-input Maintainers are waiting for feedback from author label Nov 12, 2026
@adangel adangel added this to the 7.30.0 milestone Nov 12, 2026
@pmd-actions-helper

pmd-actions-helper Bot commented Nov 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-11-12 12:27:07+00:00 for b550479)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel
Merge branch 'main' into cursor/fix-ufqn-lombok-builder-7c90
b550479
adangel
adangel approved these changes Nov 12, 2026
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel adangel self-assigned this Nov 12, 2026
@adangel
adangel merged commit 01ea262 into pmd:main Nov 12, 2026
2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 13, 2026
[java] Lombok: support @Builder on types #7241
Open
[java] Fix #7214: ClassWithOnlyPrivateConstructorsShouldBeFinal: consider Lombok private constructors #7231
Open
Pankraz76 pushed a commit to Pankraz76/pmd_fork_tmp that referenced this pull request Nov 13, 2026
@claude
Merge branch 'main' into feat/3119-lombok-builder
96146eb
Resolve the conflicts with pmd#7198, which added the (empty) builder class
of lombok.Builder. Build on that implementation instead of duplicating it:

- keep the builder class of pmd#7198, including builders of constructors
  and methods, the '*' wildcard of builderClassName and the annotation scope
- add the members for @builder on a non-generic class: the methods of the
  builder class, builder() and toBuilder()
- honor the access attribute for the builder class
- a handwritten builder class gets the methods it does not declare

Builders of generic classes, constructors and methods stay empty classes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MTr23wWTVcrESgpWPAS9iR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@oowekyala oowekyala oowekyala requested changes
@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

None yet

Projects

None yet

Milestone

7.30.0

Development

Successfully merging this pull request may close these issues.

[java] UnnecessaryFullyQualifiedName: False positive for lombok.Builder annotation

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@markjoin123 @adangel @oowekyala
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.