JDK-8133922 : found a compiler bug in switch/case statement
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-08-17
  • Updated: 2016-02-02
  • Resolved: 2015-08-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u80Resolved 8u51Resolved 9Resolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 7 [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
I wrote switch/case statemnt in wrong format but compiler raised not suitable error.

REGRESSION.  Last worked in version 7u80

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Information:Using javac 1.7.0 to compile java sources
Information:java: An exception has occurred in the compiler (1.7.0). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
Information:java: java.lang.NullPointerException
Information:java: 	at com.sun.tools.javac.comp.Lower.visitStringSwitch(Lower.java:3456)
Information:java: 	at com.sun.tools.javac.comp.Lower.visitSwitch(Lower.java:3357)
Information:java: 	at com.sun.tools.javac.tree.JCTree$JCSwitch.accept(JCTree.java:959)
Information:java: 	at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
Information:java: 	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
Information:java: 	at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
Information:java: 	at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:160)
Information:java: 	at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3311)
Information:java: 	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:781)
Information:java: 	at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:144)
Information:java: 	at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2619)
Information:java: 	at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2538)
Information:java: 	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:669)
Information:java: 	at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2283)
Information:java: 	at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:591)
Information:java: 	at com.sun.tools.javac.comp.Lower.translate(Lower.java:2180)
Information:java: 	at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3650)
Information:java: 	at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1393)
Information:java: 	at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1271)
Information:java: 	at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:870)
Information:java: 	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:829)
Information:java: 	at com.sun.tools.javac.main.Main.compile(Main.java:417)
Information:java: 	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
Information:java: 	at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:168)
Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:382)
Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:296)
Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:204)
Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:176)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1196)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:877)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:945)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:840)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:663)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:370)
Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:191)
Information:java: 	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:137)
Information:java: 	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:293)
Information:java: 	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:124)
Information:java: 	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:242)
Information:java: 	at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
Information:java: 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
Information:java: 	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
Information:java: 	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
Information:java: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
Information:java: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
Information:java: 	at java.lang.Thread.run(Thread.java:722)
Information:java: Errors occurred while compiling module 'persistence'
Information:08/17/2015 09:49 AM - Compilation completed with 1 error and 0 warnings in 3s 258ms
Error:java: Compilation failed: internal java compiler error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
switch (myString) {
            case ("a"):
                System.out.println("a");
                break;

            case ("b"):
                System.out.println("b");
                break;
}
---------- END SOURCE ----------


Comments
Sent a mail to the submitter informing about the fix in later versions.
24-08-2015

Changing to Unassigned and moving to JDK.
19-08-2015

Tested the following code on 7u80, 8u51, 8u60 EA and 9 EA - compiled and ran successfully on all the versions. Marking as duplicate. public class SwitchTest_9023530 { public static void main(String[] args) { String myString = "a"; switch (myString) { case ("a"): System.out.println("a"); break; case ("b"): System.out.println("b"); break; } System.out.println("Outside of switch"); } }
19-08-2015