Skip to content

[java] Fix #7144: Fix lambda block body compatibility - #7218

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
noor-ahmadi:fix_lambda_block_compatibility
Nov 10, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
noor-ahmadi:fix_lambda_block_compatibility

Conversation

@noor-ahmadi

Copy link
Copy Markdown
Contributor

Describe the PR

PMD was picking Runnable for an endless-loop lambda and Callable for one that could finish normally. This checks normal completion and every return so those choices match javac.

Reused the existing flow analysis while keeping constant folding out of the early symbol-table pass. The helper also needed fixes for switch fallthrough and labelled continues so valid block lambdas still work. Added the missing void-target specificity check for the endless-loop case too.

Added regression tests for the reported overloads, constant loops, return paths and nested bodies. Pattern and boolean switches are covered too.

ran ./mvnw -B -ntp -pl pmd-java -am clean verify on Java 21. 16,945 tests, 32 skipped and no failures. The baseline caught 52 failing lambda cases before the fix.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests in pmd-java and its dependencies
  • 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 Oct 22, 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, 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-10 16:45:57+00:00 for ab60efc)

@oowekyala oowekyala 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.

This looks good to me, thank you

@UncleOwen UncleOwen changed the title [java] Fix lambda block body compatibility [java] Fix #7144: Fix lambda block body compatibility Nov 10, 2026

@UncleOwen UncleOwen 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!

@UncleOwen UncleOwen added this to the 7.30.0 milestone Nov 10, 2026
@UncleOwen
UncleOwen merged commit a825ee7 into pmd:main Nov 10, 2026
13 checks passed
saryn17 added a commit to saryn17/pmd that referenced this pull request Nov 11, 2026
pmd#7144 was fixed by pmd#7218. The loop conditions (boolean) true and
ON == true move to a new disabled case, because ConstantFolder does
not fold them (pmd#7313).
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] Lambda block body that cannot complete normally is not treated as value-compatible

3 participants