-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
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
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