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

Attempting to autobox in array initializer kills compiler

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 1.4.0
    • tools
    • None
    • generic
    • generic

      The current spec does not say that it it is legal to use autoboxing (or auto-unboxing) in array initializers (though it probably should). Curiosity got the better of me, so I tried compiling the following program:

      public class Test {
          public static void main(String[] args) {
              Integer a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
          }
      }

      The compiler keeled over:

      An exception has occurred in the compiler (1.5.0-internal). 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.ArrayIndexOutOfBoundsException: -1
              at com.sun.tools.javac.jvm.Code.emitop0(Code.java:545)
              at com.sun.tools.javac.jvm.Items$StackItem.duplicate(Items.java:271)
              at com.sun.tools.javac.jvm.Gen.visitNewArray(Gen.java:1702)
              at com.sun.tools.javac.tree.Tree$NewArray.accept(Tree.java:854)
              at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:801)
              at com.sun.tools.javac.jvm.Gen.visitVarDef(Gen.java:954)
              at com.sun.tools.javac.tree.Tree$VarDef.accept(Tree.java:508)
              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:537)
              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:479)
              at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:648)
              at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2174)
              at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:322)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:464)
              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)
                                                                                      

            gafter Neal Gafter (Inactive)
            jjb Josh Bloch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: