A DESCRIPTION OF THE PROBLEM :
When a switch expression is used as a method argument, and one of its cases has a missing "break" value, the compiler throws an NPE instead of giving a sensible error message.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the following source code with "javac --enable-preview -source 12"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"missing break value" error message on line 3
ACTUAL -
An exception has occurred in the compiler (12.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 and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr$SwitchExpressionType.overloadCheck(ArgumentAttr.java:491)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr$ArgumentType.complete(ArgumentAttr.java:364)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:338)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:324)
at jdk.compiler/com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1058)
at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:885)
at jdk.compiler/com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:773)
at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:894)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:616)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1561)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1731)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1800)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1774)
at jdk.compiler/com.sun.tools.javac.comp.Resolve$10.doLookup(Resolve.java:2652)
at jdk.compiler/com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3291)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3541)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2649)
at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2643)
at jdk.compiler/com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3922)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3802)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2189)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:664)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2191)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1709)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:664)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:715)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1860)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1519)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:664)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:737)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:756)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1307)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:664)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:737)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1111)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:872)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:664)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:737)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4884)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4775)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4704)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4649)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1341)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
---------- BEGIN SOURCE ----------
class Test {
public static void main(String[] args) {
System.out.println(switch(args.length) { case 0: break; });
}
}
---------- END SOURCE ----------
FREQUENCY : always