semgrep icon indicating copy to clipboard operation
semgrep copied to clipboard

Failing to parse valid Java 21 syntax: case when statement

Open jaredstehler opened this issue 9 months ago • 1 comments

Describe the bug The semgrep parser is failing on the following valid Java 21 syntax:

  private static String calculateColor(Integer value) {
    return switch (value) {
      case Integer i when i <= -10 -> NEGATIVE_COLOR;
      case Integer i when i >= 10 -> POSITIVE_COLOR;
      default -> NEUTRAL_COLOR;
    };
  }

with the error message:

 **Semgrep encountered the following errors:**
	- Repro.java failed to parse. Does it contain a syntax error?

Verbose:
	- Syntax error at line /var/folders/q3/kq6rb1b550d7rd_pw9p7pw7c0000gq/T/tmp-371001d04VPucUAst/workspace/sources/head/MyProject/src/main/java/Repro.java:49:
 `-10 ->` was unexpected

To Reproduce Steps to reproduce the behavior, ideally a link to https://semgrep.dev:

https://semgrep.dev/playground/r/pKU1ven/hubspot.java-21-parse-fail-case-when

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

What is the priority of the bug to you?

  • [x] P0: blocking your adoption of Semgrep or workflow
  • [ ] P1: important to fix or quite annoying
  • [ ] P2: regular bug that should get fixed

Environment Observed with semgrep python package up to 1.74.0, and on semgrep.dev.

Use case What will fixing this bug enable for you?

jaredstehler avatar May 24 '24 16:05 jaredstehler