Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8222169

java.lang.AssertionError switch expression in ternary operator - ?

    Details

    • Subcomponent:
    • Resolved In Build:
      b22
    • Verification:
      Verified

      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


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlahoda Jan Lahoda
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: