Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 6.1.7601] EXTRA RELEVANT SYSTEM CONFIGURATION : PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 6, GenuineInte PROCESSOR_LEVEL=6 PROCESSOR_REVISION=1706 ProgramData=C:\ProgramData ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) ProgramW6432=C:\Program Files SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\Windows A DESCRIPTION OF THE PROBLEM : Running javac on a program which contains a string literal enclosed in parenthesis like in the example listed below causes javac to throw NullPointerException and terminate. ... switch (s) { case ("xyz"): // enclosing the string literal in parenthesis causes javac to crash ... } ... Note: - Removing the parenthesis from this program helps resolve the issue. - Replacing the String with int in the example will not reproduce this issue and hence using parenthesis with int literal in 'case' is handled well. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Create a file named Test.java with the following content: === Begin file Test.java === public class Test { public static void main(String args[]) { switch(args[0]) { case("hello"): System.out.println("hello!!"); break; default: System.out.println("hi!"); } } } === End of file Test.java === Save the file and execute the following from the command prompt: javac Test.java EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Test.class is expected to be created as a result of successful compilation. ACTUAL - javac crashes with the following error message: C:\Temp>"C:\Program Files (x86)\Java\jdk1.7.0\bin\javac.exe" Test.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. 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) C:\Temp> ERROR MESSAGES/STACK TRACES THAT OCCUR : C:\Temp>"C:\Program Files (x86)\Java\jdk1.7.0\bin\javac.exe" Test.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. 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) C:\Temp> REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- // // File name: Test.java // public class Test { public static void main(String args[]) { switch(args[0]) { case("hello"): System.out.println("hello!!"); break; default: System.out.println("hi!"); } } } === End of file Test.java === ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Remove the parenthesis from around the sting literal: === Begin file Test.java === public class Test { public static void main(String args[]) { switch(args[0]) { case "hello": // workaround is to remove the parenthesis System.out.println("hello!!"); break; default: System.out.println("hi!"); } } } === End of file Test.java ===
|