-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
11
A DESCRIPTION OF THE PROBLEM :
Using an switch-on-enum syntax causes all enums that are referenced by switch-on-enum to load. This is not allowed by JLS, as JLS in https://docs.oracle.com/javase/specs/jls/se11/html/jls-12.html#jls-12.4 says that "A class or interface will not be initialized under any other circumstance".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the executable test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should throw null pointer exception without showing any text.
ACTUAL -
It shows `Bar` followed by `Foo`.
---------- BEGIN SOURCE ----------
enum Foo {
;
static {
System.out.println("Foo");
}
}
enum Bar {
;
static {
System.out.println("Bar");
}
}
public class Example {
public static void main(String[] args) {
switch ((Foo) null) {}
switch ((Bar) null) {}
}
}
---------- END SOURCE ----------
FREQUENCY : always
Using an switch-on-enum syntax causes all enums that are referenced by switch-on-enum to load. This is not allowed by JLS, as JLS in https://docs.oracle.com/javase/specs/jls/se11/html/jls-12.html#jls-12.4 says that "A class or interface will not be initialized under any other circumstance".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the executable test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should throw null pointer exception without showing any text.
ACTUAL -
It shows `Bar` followed by `Foo`.
---------- BEGIN SOURCE ----------
enum Foo {
;
static {
System.out.println("Foo");
}
}
enum Bar {
;
static {
System.out.println("Bar");
}
}
public class Example {
public static void main(String[] args) {
switch ((Foo) null) {}
switch ((Bar) null) {}
}
}
---------- END SOURCE ----------
FREQUENCY : always
- duplicates
-
JDK-8219412 Eager enum class initialization with enum switch
- Open