-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
17
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Ubuntu 20.04, Java 17.0.1 (openjdk)
A DESCRIPTION OF THE PROBLEM :
When trying to compile a Java file with a nested switch expression (see the reproduce section), the Java compiler fails with a NullPointerException:
```
An exception has occurred in the compiler (17.0.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.isEnum()" because "expr.sym" is null
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Invoke javac TestFile.java (the content of which is pasted in source code below)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions, a compiled Java file.
ACTUAL -
A Nullpointer exception:
An exception has occurred in the compiler (17.0.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.isEnum()" because "expr.sym" is null
---------- BEGIN SOURCE ----------
public class EnumSwitchTestCase {
enum Type {
FIRST
}
enum Subtype {
A,
B
}
enum ResultType {
ONE,
TWO
}
interface Method {
Type type();
}
record FirstMethod(Subtype subtype) implements Method {
@Override
public Type type() {
return Type.FIRST;
}
}
record Something(Method method) {}
record Entity(ResultType resultType) {}
public static void main(final String[] args) {
final var something = new Something(new FirstMethod(Subtype.A));
final Entity entity =
new Entity(
switch (something.method().type()) {
case FIRST -> switch (((FirstMethod) something.method()).subtype()) {
case A -> ResultType.ONE;
case B -> ResultType.TWO;
};
});
System.out.println(entity);
}
}
---------- END SOURCE ----------
FREQUENCY : always
Ubuntu 20.04, Java 17.0.1 (openjdk)
A DESCRIPTION OF THE PROBLEM :
When trying to compile a Java file with a nested switch expression (see the reproduce section), the Java compiler fails with a NullPointerException:
```
An exception has occurred in the compiler (17.0.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.isEnum()" because "expr.sym" is null
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Invoke javac TestFile.java (the content of which is pasted in source code below)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions, a compiled Java file.
ACTUAL -
A Nullpointer exception:
An exception has occurred in the compiler (17.0.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.isEnum()" because "expr.sym" is null
---------- BEGIN SOURCE ----------
public class EnumSwitchTestCase {
enum Type {
FIRST
}
enum Subtype {
A,
B
}
enum ResultType {
ONE,
TWO
}
interface Method {
Type type();
}
record FirstMethod(Subtype subtype) implements Method {
@Override
public Type type() {
return Type.FIRST;
}
}
record Something(Method method) {}
record Entity(ResultType resultType) {}
public static void main(final String[] args) {
final var something = new Something(new FirstMethod(Subtype.A));
final Entity entity =
new Entity(
switch (something.method().type()) {
case FIRST -> switch (((FirstMethod) something.method()).subtype()) {
case A -> ResultType.ONE;
case B -> ResultType.TWO;
};
});
System.out.println(entity);
}
}
---------- END SOURCE ----------
FREQUENCY : always
- duplicates
-
JDK-8274347 Passing a *nested* switch expression as a parameter causes an NPE during compile
-
- Resolved
-