GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #6364

New issue
Copy link
New issue
Copy link
Closed
#6430
Closed
[java] Parse error with yield lambda inside switch#6364
#6430
Copy link
Assignees
oowekyala
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
7.21.0

Description

@kelunik
kelunik
opened on Dec 30, 2025
Issue body actions

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.

Activity

  1. kelunik
    added
    a:bugPMD crashes or fails to analyse a file.
    on Dec 30, 2025
  2. adangel commented on Dec 30, 2025

    @adangel
    adangel
    on Dec 30, 2025
    Member
    More actions

    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?

  3. kelunik commented on Jan 2, 2026

    @kelunik
    kelunik
    on Jan 2, 2026
    ContributorAuthor
    More actions

    Oops, I've updated the example.

    Reacted by Andreas Dangel
  4. adangel
    added
    in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception
    on Jan 5, 2026
  5. oowekyala
    self-assigned this
    on Jan 8, 2026
  6. oowekyala
    added a commit that references this issue on Jan 8, 2026

    [java] Fix pmd#6364 - parse error with yield lambda

    This issue will close once commit 3e7d559 is merged into the 'main' branch.
    3e7d559
  7. oowekyala
    added this to the 7.21.0 milestone on Jan 8, 2026
  8. adangel
    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, 2026
  9. adangel
    closed this as completedin 3e7d559on Jan 29, 2026
  10. adangel
    added 2 commits that reference this issue on Jan 29, 2026

    [doc] Update release notes (#6364, #6430)

    ab25066

    [java] Fix #6364: Parse error with yield lambda (#6430)

    569068a
  11. wener-tiobe
    added a commit that references this issue on Feb 10, 2026

    RM-37163: CPD 7.21.0 upgrade (#8)

    This issue will close once commit 6a1959a is merged into the 'tiobe_pmd7' branch.
    6a1959a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @oowekyala
    oowekyala

Labels

a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception

Type

No type

Projects

No projects

    Milestone

    • 7.21.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.