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

Primitive arrays and varargs inference leads to crash in TreeMaker.Type(TreeMaker.java:531)

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
      5.0
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The compiler crashes when compiling this code:

      public class GenericsBug {
        
        static <T> void varargs(T...args){
          for(T t : args)
            System.out.println(t);
        }
        
        public static void main(String[]args){
          varargs(new int[]{1, 2, 3}, new int[]{4, 5, 6});
        }
        
      }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just try to compile the code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Since the method:
      static <T> void varargs(T...args)
      should be translated by the compiler to:
      static void varargs(Object...args)
      and arrays are objects then this code should compile, otherwise the compiler should report an error, but not crash!!
      ACTUAL -
      An exception has occurred in the compiler (1.5.0). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.AssertionError: unexpected type: <nulltype>
      at com.sun.tools.javac.tree.TreeMaker.Type(TreeMaker.java:531)
      at com.sun.tools.javac.tree.TreeMaker.Type(TreeMaker.java:525)
      at com.sun.tools.javac.comp.Lower.boxArgs(Lower.java:2529)
      at com.sun.tools.javac.comp.Lower.visitApply(Lower.java:2439)
      at com.sun.tools.javac.tree.Tree$Apply.accept(Tree.java:819)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:227)
      at com.sun.tools.javac.tree.Tree$Exec.accept(Tree.java:734)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:54)
      at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:145)
      at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:2950)
      at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:540)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:129)
      at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2287)
      at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2206)
      at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:482)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2001)
      at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:438)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1913)
      at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3087)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:462)
      at com.sun.tools.javac.main.Main.compile(Main.java:592)
      at com.sun.tools.javac.main.Main.compile(Main.java:544)
      at com.sun.tools.javac.Main.compile(Main.java:58)
      at com.sun.tools.javac.Main.main(Main.java:48)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.5.0). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.AssertionError: unexpected type: <nulltype>
      at com.sun.tools.javac.tree.TreeMaker.Type(TreeMaker.java:531)
      at com.sun.tools.javac.tree.TreeMaker.Type(TreeMaker.java:525)
      at com.sun.tools.javac.comp.Lower.boxArgs(Lower.java:2529)
      at com.sun.tools.javac.comp.Lower.visitApply(Lower.java:2439)
      at com.sun.tools.javac.tree.Tree$Apply.accept(Tree.java:819)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:227)
      at com.sun.tools.javac.tree.Tree$Exec.accept(Tree.java:734)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:54)
      at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:145)
      at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:2950)
      at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:540)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:129)
      at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2287)
      at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2206)
      at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:482)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2001)
      at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:438)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1893)
      at com.sun.tools.javac.comp.Lower.translate(Lower.java:1913)
      at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3087)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:462)
      at com.sun.tools.javac.main.Main.compile(Main.java:592)
      at com.sun.tools.javac.main.Main.compile(Main.java:544)
      at com.sun.tools.javac.Main.compile(Main.java:58)
      at com.sun.tools.javac.Main.main(Main.java:48)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class GenericsBug {
        
        static <T> void varargs(T...args){
          for(T t : args)
            System.out.println(t);
        }
        
        public static void main(String[]args){
          varargs(new int[]{1, 2, 3}, new int[]{4, 5, 6});
        }
        
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I don't have any, but not to use varargs
      Hint: When I used the Integer wrapper, it woked, i.e,
      varargs(new Integer[]{1, 2, 3}, new Integer[]{4, 5, 6});
      instead of:
      varargs(new int[]{1, 2, 3}, new int[]{4, 5, 6});
      ###@###.### 2005-1-28 06:42:25 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ahe Peter Ahe
              Reporter:
              jssunw Jitender S (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: