You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] LambdaCanBeMethodReference: False positive with array creation containing constructor call in receiver #6709
Description:
The rule reports a false positive for a lambda whose method-call receiver contains an array creation expression with a nested constructor call.
The official documentation explicitly states that the rule will not report lambdas of the form x -> new CtorCall().something(x) because converting to a method reference would change the object creation timing (one object at method-ref creation time vs. one object per lambda invocation).
This reproducer has exactly the same semantic issue, but the constructor call is hidden inside an array initializer (new Holder[] { new Holder() }[0]). The current implementation in canBeTransformed() only excludes a top-level ASTConstructorCall and therefore incorrectly suggests the transformation.
Expected outcome:
PMD should not report any violation.
The suggested method reference new Holder[]{ new Holder() }[0]::test changes the program semantics (array + Holder are created only once instead of on every lambda invocation). This is a false positive.
changed the title [-][java] LambdaCanBeMethodReference false positive with array creation containing constructor call in receiver[/-][+][java] LambdaCanBeMethodReference: False positive with array creation containing constructor call in receiver[/+]on May 25, 2026
Activity
[-][java] LambdaCanBeMethodReference false positive with array creation containing constructor call in receiver[/-][+][java] LambdaCanBeMethodReference: False positive with array creation containing constructor call in receiver[/+]Fix false positive: LambdaCanBeMethodReference should not flag lambda…
Fix false positive: LambdaCanBeMethodReference should not flag lambda… (