JDK-8037404 : javac NPE or VerifyError for code with constructor reference of inner class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-03-14
  • Updated: 2015-01-21
  • Resolved: 2014-06-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b22Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Try to compile following codes. 

import java.util.function.Supplier;
import java.util.stream.Stream;

public class Issue {
    public static void main(String[] args) {
        System.out.println(new Issue().getList().get());
    }

    Supplier<TT> getList() {
        return () -> Stream.of(1).map(TT::new).findFirst().get();
    }

    class TT {
        public TT(int i) {

        }
    }
}
////////////////////////////////////
import java.util.function.Function;
import java.util.stream.Stream;

public class Issue {
    public static void main(String[] args) {
        System.out.println(new Issue().map().apply(1));
    }

    Function<Integer,TT> map() {
        return (i) -> Stream.of(i).map(TT::new).findFirst().get();
    }

    class TT {
        public TT(int i) {

        }
    }
}

//////////////////////////////////////////
java.lang.NullPointerException
        at com.sun.tools.javac.jvm.Code.emitop0(Code.java:563)
        at com.sun.tools.javac.jvm.Items$SelfItem.load(Items.java:367)
        at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:966)
        at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1905)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1459)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:966)
        at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1905)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1459)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.visitSelect(Gen.java:2404)
        at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1891)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1900)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1459)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.visitTypeCast(Gen.java:2327)
        at com.sun.tools.javac.tree.JCTree$JCTypeCast.accept(JCTree.java:1808)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:947)
        at com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1863)
        at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1378)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:737)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:772)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:758)
        at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:809)
        at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1158)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:903)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:737)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:772)
        at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:1031)
        at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:994)
        at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:772)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:737)
        at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2526)
        at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:748)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1570)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1534)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:904)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:863)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at com.sun.tools.javac.Main.main(Main.java:42)

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Issue.lambda$map$0(Ljava/lang/Integer;)LIssue$TT; @5: invokedynamic
  Reason:
    Type 'java/lang/Integer' (current frame, stack[1]) is not assignable to 'Issue'
  Current Frame:
    bci: @5
    flags: { }
    locals: { 'java/lang/Integer' }
    stack: { 'java/util/stream/Stream', 'java/lang/Integer' }
  Bytecode:
    0000000: 2ab8 000a 2aba 000b 0000 b900 0c02 00b9
    0000010: 000d 0100 b600 0ec0 000f b0            

Comments
Test(s) was added with this push --- URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/2b6b96ed3878 User: rfield Date: 2014-06-25 18:22:47 +0000
27-06-2014

SQE is ok to defer from 8u20.
18-06-2014

Need SQE-OK and indication of what release this will be fixed in.
18-06-2014

8u20-defer-request: 8037404, 8038776, 8044737, and 8044748 form a cluster of issues related to inadequate handling of constructor references to nested classes in method references. They cause crashes of the compiler and/or the running user code, and thus are high impact. They have been reported in at least five cases in fully supported code and thus this is medium likelihood. The workaround is to manually convert them to lambdas which is a low hurdle workaround. Thus ILM of HML. The fix requires rearchitecting of how method references are handled, with hundreds of lines of code change, and thus is inappropriate for an update release. The fix is under review for push to JDK9.
16-06-2014

There are two distinct, if possibly related, issues here. The latter issue appears to be a duplicate of JDK-8038776
29-05-2014

I think this is in Robert's area, reassigning.
28-05-2014

Here's a minimal way to get the NullPointerException crash. I get the same stack trace as in the description (jdk8-b132). import java.util.function.Supplier; public class Test { public static void main(String[] args) { new Test().x(); } void x() { Supplier<?> r = () -> (Supplier<Object>)Inner::new; } class Inner { } }
30-03-2014

Incident JI-9011425 is possibly a duplicate of this one.
30-03-2014

Release team: Approved for deferral.
21-03-2014