JDK-8015928 : switch statement bug
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-05-08
  • Updated: 2015-08-19
  • Resolved: 2013-06-05
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
when I want to chech string variables in switch statement like that:

 public void doJob( String foo )
 {
      switch (methodName)
      {
    case ( " A " ): // wrong string comparison, decleration error (*)
    {
    doAJob();
    }break;
    case  " B " :  // string comparison right
                {
         doBJob();
    } break;
    default :
     System.err.println( " No such param " );
}
 }

(*) At line 7: there is a syntax error but javac can't understand it. It says  " An exception has occurred in the compiler (1.7.0_01) "  . But I tried the code in java version  " 1.5.0_05 "  . It can see the decleration error.


REGRESSION.  Last worked in version 5.0


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException

    at com.sun.tools.javac.comp.Lower.visitStringSwitch(Lower.java:3456)

    at com.sun.tools.javac.comp.Lower.visitSwitch(Lower.java:3357)

    at com.sun.tools.javac.tree.JCTree$JCSwitch.accept(JCTree.java:959)

    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)

    at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)

    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)

    at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:160)

    at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3311)

    at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:781)

    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)

    at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)

    at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:144)

    at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2619)

    at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2538)

    at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:669)

    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)

    at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)

    at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2283)

    at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:591)

    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)

    at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)

    at com.sun.tools.javac.comp.Lower.translate(Lower.java:2180)

    at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3650)

    at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1393)

    at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1271)

    at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:870)

    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:829)

    at com.sun.tools.javac.main.Main.compile(Main.java:417)

    at com.sun.tools.javac.main.Main.compile(Main.java:331)

    at com.sun.tools.javac.main.Main.compile(Main.java:322)

    at com.sun.tools.javac.Main.compile(Main.java:76)

    at com.sun.tools.javac.Main.main(Main.java:61)


REPRODUCIBILITY :
This bug can be reproduced always.

SUPPORT :
YES
Comments
Assume the customer is reporting JDK-7071246; closing as a duplicate.
05-06-2013

Clearly not a regression, since strings in switch was not available in 5
04-06-2013