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

java.lang.AssertionError on Ternary operator with decrement

    XMLWordPrintable

Details

    • 12
    • x86_64
    • windows_7

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 7 64 bit / jdk - 12.0.2

      A DESCRIPTION OF THE PROBLEM :
      When, in the code, there is a ternary operator that operates a decrement on a variable, the compiler crashes.

      REGRESSION : Last worked in version 8u221

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      private Long maxNumberOfUnits = null; ---> class variable

      public void reduceValues() ---> class method
        {
          maxNumberOfUnits = maxNumberOfUnits == null ? 0L : maxNumberOfUnits--;
         
        }

      but the problem appears also if the variable is not a class one, for example:

      public void reduceValues() ---> class method
        {
          long test = maxNumberOfUnits == null ? 0L : maxNumberOfUnits--;
         
        }



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      compiling
      ACTUAL -
       Compilation failure:
       An exception has occurred in the compiler (12.0.2). 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.
      e 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.visitSelect(Gen.java:2241)
               at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2189)
               at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853)
               at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1803)
               at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1709)
               at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:853)
               at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitVarDef(Gen.java:1051)
               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.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 QuantitiesDto {
      private Long maxNumberOfUnits = null;

      public void reduceValues()
        {
          maxNumberOfUnits = maxNumberOfUnits == null ? 0L : maxNumberOfUnits--;
         
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      if(maxNumberOfUnits == null) {
      maxNumberOfUnits = 0L;
      }
      else {
      maxNumberOfUnits--;
      }

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              fmatte Fairoz Matte
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: