Pattern matching for switch: Spec and Javac inconsistency regarding enhanced switch statements

Ilyas Selimov ilyas.selimov at
Wed Jul 7 07:17:41 UTC 2021


I found a difference between completeness rules for enhanced switch
statements in spec draft (
and its javac implementation (OpenJDK 17 build 17-ea+29-2576).

> An enhanced switch statement is one where either (i) the type of the
selector expression is not char, byte, short, int, Character, Byte, Short,
Integer, String, or an enum type,
or (ii) at least one of the switch labels has a pattern case label element
or a null case label element.

According to the statement, the next switch statement is enhanced:
void test(String s) {
  switch (s) {
    case null:

> If the switch statement is an enhanced switch statement, then the switch
block must be complete for the selector expression.

As one contains neither total pattern, nor default label, it's incomplete,
but javac compiles it correctly.
Maybe I missed PR that fixed the issue.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list