Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8290709

Incorrect dominance error for unconditional pattern vs. null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 20
    • 19, 20
    • tools
    • None
    • b14

      As reported here:
      https://mail.openjdk.org/pipermail/amber-spec-experts/2022-July/003479.html

      Consider this code:
      ---
      public class Main {
        public static void main(String[] args) {
          Integer x = null;
          switch (x) {
            case Integer i -> System.out.println(i);
            case null -> System.out.println("null is supplied!");
          }
        }
      }
      ---

      This should compile, but does not:
      ---
      $ javac --enable-preview -source 20 /tmp/Main.java
      /tmp/Main.java:6: error: this case label is dominated by a preceding case label
      case null -> System.out.println("null is supplied!");
           ^
      Note: /tmp/Main.java uses preview features of Java SE 20.
      Note: Recompile with -Xlint:preview for details.
      1 error
      ---

            abimpoudis Angelos Bimpoudis
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: