Repository navigation
Closed
Labels
a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception
Milestone
Description
Affects PMD Version:
PMD 7.20.0 (fa478ec, 2025-12-30T14:37:52Z)
Description:
Parsing code fails while it is valid Java.
Exception Stacktrace:
[WARN] This analysis could be faster, please consider using Incremental Analysis: https://docs.pmd-code.org/pmd-doc-7.20.0/pmd_userdocs_incremental_analysis.html
../tools/build/Lambda.java - ParseException: Parse exception in file '../tools/build/Lambda.java' at line 6, column 27: Encountered <IDENTIFIER: "a">.
Was expecting one of:
"instanceof" ...
")" ...
"," ...
"=" ...
"<" ...
"?" ...
"==" ...
"<=" ...
">=" ...
"!=" ...
"||" ...
"&&" ...
"++" ...
"--" ...
"+" ...
"-" ...
"*" ...
"/" ...
"&" ...
"|" ...
"^" ...
"%" ...
"+=" ...
"-=" ...
"*=" ...
"/=" ...
"&=" ...
"|=" ...
"^=" ...
"%=" ...
"<<=" ...
">>=" ...
">>>=" ...
">" ...
[INFO] An error occurred while executing PMD.
Code Sample demonstrating the issue:
public class Lambda {
public static void main( String[] args ) {
foo(switch ( args[0] ) {
default:
yield (Lambda a, Lambda b) -> "hello";
});
}
private static void foo(java.util.function.BiFunction<Lambda, Lambda, String> f) {}
}Rules
<?xml version="1.0"?>
<ruleset name="Custom Rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Dead code
</description>
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod">
<properties>
<property name="ignoredAnnotations" value="jakarta.annotation.PostConstruct,jakarta.annotation.PreDestroy" />
</properties>
</rule>
</ruleset>Steps to reproduce:
Run pmd check -f text -R deadcode.xml -d testdir. Running on Java 25.
Having a single parameter in the lambda does not trigger the parse error.
Metadata
Metadata
Assignees
Labels
a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception
Activity
adangel commentedon Dec 30, 2025
The code sample does not compile with java:
you are yielding a lambda from the switch expression, which is not a suitable argument for println...
Can you make an example, that compiles?
kelunik commentedon Jan 2, 2026
Oops, I've updated the example.
[java] Fix pmd#6364 - parse error with yield lambda
[-][java] Failure to parse lambda expression with multiple parameters inside switch expression[/-][+][java] Parse error with yield lambda inside switch[/+][doc] Update release notes (#6364, #6430)
[java] Fix #6364: Parse error with yield lambda (#6430)
RM-37163: CPD 7.21.0 upgrade (#8)