Skip to content

[java] Fix #7120: NonThreadSafeSingleton NoSuchElementException - #7121

Merged
adangel merged 6 commits into
pmd:mainfrom
UncleOwen:issue-7120-NonThreadSafeSingleton-NPE
Oct 23, 2026
Merged

adangel merged 6 commits into
pmd:mainfrom
UncleOwen:issue-7120-NonThreadSafeSingleton-NPE

Conversation

@UncleOwen

Copy link
Copy Markdown
Member

Describe the PR

This fixes a NoSuchElementException in NonThreadSafeSingleton

The code assumed that every ASTVariableId of a JFieldSymbol is inside a ASTFieldDeclaration. This assumption is wrong for records. Records are thread-safe by default, so we can safely return false from shouldConsiderField.

Related issues

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)

@pmd-actions-helper

pmd-actions-helper Bot commented Sep 28, 2026 •

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, 16 errors and 9 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-10-23 14:03:01+00:00 for 1dabcf5)

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@adangel adangel added this to the 7.29.0 milestone Oct 23, 2026
@adangel
adangel merged commit 46cfb1d into pmd:main Oct 23, 2026
2 checks passed
@UncleOwen
UncleOwen deleted the issue-7120-NonThreadSafeSingleton-NPE branch October 23, 2026 14:03
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.

[java] NonThreadSafeSingleton: throws NoSuchElementException on a record that null checks its own fields

2 participants