JDK-8222169 : java.lang.AssertionError switch expression in ternary operator - ?
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 12,13
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-04-05
  • Updated: 2019-08-13
  • Resolved: 2019-05-16
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 13
13 b22Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
uname -a
Linux tinkywinky 3.10.0-862.11.6.el7.x86_64 #1 SMP Fri Aug 10 16:55:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

 javac --version
Picked up JAVA_TOOL_OPTIONS: --enable-preview
javac 12

A DESCRIPTION OF THE PROBLEM :
The following code fails to compile:
package com.rockwellcollins.ana.gui;

public class A
{
   static String a;
   static String b;
   
   static
   {
      A.a = "not me";

      A.b =
         A.a == null
            ? null
            : switch( "not me" )
              {
                 default -> null;
              };
   }
}



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
 javac --enable-preview --release 12 -d classes A.java 

where A.java contains:
public class A
{
   static String a;
   static String b;
   
   static
   {
      A.a = "not me";

      A.b =
         A.a == null
            ? null
            : switch( "not me" )
              {
                 default -> null;
              };
   }
}




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful compilation
ACTUAL -
Picked up JAVA_TOOL_OPTIONS: --enable-preview
Note: A.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
An exception has occurred in the compiler (12). 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.AssertionError
	at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
	at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitVarDef(Gen.java:1053)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:962)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitLetExpr(Gen.java:2300)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$LetExpr.accept(JCTree.java:3026)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitConditional(Gen.java:1835)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1452)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitAssign(Gen.java:1951)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAssign.accept(JCTree.java:1953)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1702)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1519)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1067)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1067)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:937)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:900)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:872)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2345)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:756)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1635)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1603)
	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 ----------
public class A
{
   static String a;
   static String b;
   
   static
   {
      A.a = "not me";

      A.b =
         A.a == null
            ? null
            : switch( "not me" )
              {
                 default -> null;
              };
   }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Code without switch expression in ternary operator.

FREQUENCY : always



Comments
Steps to reproduce issue - javac --enable-preview --release 12 -d classes A.java This issue is reproducible on jdk 13 also. Possibly caused due to changes of JDK-8192963 javac crash on 13 == -sh-4.2$ /scratch/fairoz/JAVA/jdk13/jdk-13-ea+15/bin/javac --enable-preview --release 13 -d classes A.java Note: A.java uses preview language features. Note: Recompile with -Xlint:preview for details. An exception has occurred in the compiler (13-ea). 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.AssertionError at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155) at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitVarDef(Gen.java:1053) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:962) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitLetExpr(Gen.java:2300) at jdk.compiler/com.sun.tools.javac.tree.JCTree$LetExpr.accept(JCTree.java:3026) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitConditional(Gen.java:1835) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1452) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitAssign(Gen.java:1951) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAssign.accept(JCTree.java:1953) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1702) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1519) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1067) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1067) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:937) at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:900) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:872) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595) at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2345) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:756) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1640) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1608) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:972) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:318) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176) at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57) at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
09-04-2019