GeezerVison is showing github.com — [java] Parse error with yield lambda inside switch · Issue #6364 · pmd/pmd
[java] Parse error with yield lambda inside switch #6364Labels a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception DescriptionAffects 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. Activityadangel commented on Dec 30, 2025 The code sample does not compile with java:
Lambda.java:4: error: no suitable method found for println(<none>)
System.out.println(switch ( args[0] ) {
^
method PrintStream.println() is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(boolean) is not applicable
(argument mismatch; boolean is not a functional interface)
method PrintStream.println(char) is not applicable
(argument mismatch; char is not a functional interface)
method PrintStream.println(int) is not applicable
(argument mismatch; int is not a functional interface)
method PrintStream.println(long) is not applicable
(argument mismatch; long is not a functional interface)
method PrintStream.println(float) is not applicable
(argument mismatch; float is not a functional interface)
method PrintStream.println(double) is not applicable
(argument mismatch; double is not a functional interface)
method PrintStream.println(char[]) is not applicable
(argument mismatch; Array is not a functional interface)
method PrintStream.println(String) is not applicable
(argument mismatch; String is not a functional interface)
method PrintStream.println(Object) is not applicable
(argument mismatch; Object is not a functional interface)
1 error
error: compilation failed
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 commented on Jan 2, 2026 ContributorAuthor More actions Oops, I've updated the example. Reacted by Andreas Dangel added a commit that references this issue on Jan 8, 2026This issue will close once commit 3e7d559 is merged into the 'main' branch.3e7d559 changed the title [-][java] Failure to parse lambda expression with multiple parameters inside switch expression[/-] [+][java] Parse error with yield lambda inside switch[/+] on Jan 29, 2026added a commit that references this issue on Feb 10, 2026This issue will close once commit 6a1959a is merged into the 'tiobe_pmd7' branch.6a1959a
MetadataMetadataa:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception DevelopmentNo branches or pull requestsIssue actions
|