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

Inconsistent case label domination check for null case

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • tools
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 22.04.2 LTS
      openjdk version "20-internal" 2023-03-21
      OpenJDK Runtime Environment (build 20-internal-adhoc.admin1.jdk-jdk-20-34)
      OpenJDK 64-Bit Server VM (build 20-internal-adhoc.admin1.jdk-jdk-20-34, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      The new pattern switch feature has additional checks to make sure that case labels are not dominated by previous case labels. For example, if the default case is not the last one or an Object instance case comes before an Integer case, then there will be the error: this case label is dominated by a preceding case label.
      However, for the null case there seems to be no such checks. It would be good, if there is also an error message if the null case is not the first one as illustrated in the following example.


      ---------- BEGIN SOURCE ----------
      Object o= null;
      switch (o) {
      case String s: System.out.println("case 1");
      case null: System.out.println("null case"); break;
      case Integer i: System.out.println("case 2"); break;
      default: System.out.println("default"); break;
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: