Potential Compiler Bug

Richard Warburton richard.warburton at gmail.com
Thu Nov 24 14:35:59 PST 2011


When running lambda binary b1314 I've generated a compiler exception 
that appears to be to do with code generation for unboxed method 
references.  Note that if you comment out the line that refers to the 
unboxed method reference it compiles without error, but if you leave it 
in then it generates a stack trace.  Code:

public class BoxingBug {

     static interface Function<R,A> {
         public R apply(A a);
     }

     public static int incUnboxed(int x) {
         return x + 1;
     }

     public static Integer incBoxed(Integer x) {
         return x + 1;
     }

     public static void main(String [] args) {
         // Use of method references
         useFunc(BoxingBug#incBoxed);
         // If you comment out this line it compiles without error
         useFunc(BoxingBug#incUnboxed);
     }

     public static void useFunc(Function<Integer,Integer> f) {
         System.out.println(f.apply(1));
     }

}

Stack Trace:

An exception has occurred in the compiler (1.8.0-ea). 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.ArrayIndexOutOfBoundsException: -1
     at com.sun.tools.javac.jvm.Code$State.pop(Code.java:1725)
     at com.sun.tools.javac.jvm.Code.emitop0(Code.java:661)
     at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:260)
     at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:273)
     at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:844)
     at com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1669)
     at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1266)
     at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:689)
     at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:724)
     at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:710)
     at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:761)
     at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1040)
     at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:792)
     at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:689)
     at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:724)
     at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:918)
     at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:890)
     at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:676)
     at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:689)
     at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2256)
     at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:727)
     at 
com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1466)
     at 
com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1434)
     at 
com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:885)
     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:844)
     at com.sun.tools.javac.main.Main.compile(Main.java:430)
     at com.sun.tools.javac.main.Main.compile(Main.java:344)
     at com.sun.tools.javac.main.Main.compile(Main.java:335)
     at com.sun.tools.javac.Main.compile(Main.java:76)
     at com.sun.tools.javac.Main.main(Main.java:61)

I hope this is helpful. I noted that an trying to force an unboxed 
lambda to be converted to a boxed SAM type (eg Function<Integer,Integer> 
unboxed = (int x) -> (int) (x + 1);) generated a compiler error, and I 
presume this should be the case with method references as well?

regards,

   Richard


More information about the lambda-dev mailing list