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

void in ternaty operator causing javac crash

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 5.0
    • tools
    • b40
    • generic
    • solaris_8

      In certain situations javac with -source 1.5 throws an assertion instead of reporting an error when the last sub-expression of a ternary expression is of type void. Also if the condition is a constant true, no error is reported. -source 1.4 correctly reports the error.

      cat > TriVoid.javac
      import javax.swing.*;
      class TriVoid {
          static void fn() {
              SpringLayout.Constraints cons1 = null;
              SpringLayout.Constraints cons2 = null;
              cons2.setY(
                  1==0 ? Spring.constant(0) : cons1.setY(Spring.constant(0))
              );
          }
      }

      javac -source 1.4 TriVoid.java

      TriVoid.java:7: incompatible types for ?: neither is a subtype of the other
      second operand: javax.swing.Spring
      third operand : void
                  1==0 ? Spring.constant(0) : cons1.setY(Spring.constant(0))
                       ^
      1 error

      javac -source 1.5 TriVoid.java

      An exception has occurred in the compiler (1.5.0-beta). Please file a bug at the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.AssertionError
              at com.sun.tools.javac.jvm.Items$Item.load(Items.java:183)
              at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:227)
              at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:246)
              at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:803)
              at com.sun.tools.javac.jvm.Gen.visitTypeCast(Gen.java:2011)
              at com.sun.tools.javac.tree.Tree$TypeCast.accept(Tree.java:934)
              at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:801)
              at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:819)
              at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1648)
              at com.sun.tools.javac.tree.Tree$Apply.accept(Tree.java:808)
              at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:801)
              at com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1596)
              at com.sun.tools.javac.tree.Tree$Exec.accept(Tree.java:725)
              at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:648)
              at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:683)
              at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:669)
              at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:720)
              at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:967)
              at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:531)
              at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:648)
              at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:683)
              at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:905)
              at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:841)
              at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:473)
              at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:648)
              at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2167)
              at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:321)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:460)
              at com.sun.tools.javac.main.Main.compile(Main.java:584)
              at com.sun.tools.javac.main.Main.compile(Main.java:536)
              at com.sun.tools.javac.Main.compile(Main.java:41)
              at com.sun.tools.javac.Main.main(Main.java:32)

            tballsunw Tom Ball (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: