JDK-8073755 : Constructor reference doesn't work with non-static inner class.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u31
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-11
  • Updated: 2015-06-01
  • Resolved: 2015-06-01
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 9
9 b22Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Constructor reference doesn't work with non-static inner class. Trying to do that will cause a java.lang.BootstrapMethodError. See the sample code.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the sample code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"OK" is printed.
ACTUAL -
Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
	at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
	at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
	at zhyi.Test$Inner.call(Test.java:18)
	at zhyi.Test$Inner.access$100(Test.java:16)
	at zhyi.Test.main(Test.java:9)
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting class zhyi.Test$Inner, found class zhyi.Test
	at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:256)
	at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
	at java.lang.invoke.CallSite.makeSite(CallSite.java:289)
	... 4 more
Java Result: 1

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package zhyi;

import java.util.function.Supplier;

public class Test {
    private Inner inner = new Inner();

    public static void main(String[] args) {
        new Test().inner.call();
    }

    private void print(Supplier<?> s) {
        System.out.println(s.get());
    }

    private class Inner {
        private void call() {
            print(Bean::new);    // Error!
            // print(() -> new Bean());    // Works fine.
        }
    }

    private class Bean {
        @Override
        public String toString() {
            return "OK";
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use normal lambda expression instead of constructor reference.


Comments
Same as https://bugs.openjdk.java.net/browse/JDK-8047341
01-06-2015

This got fixed in 9b22. @Pardeep, This cannot be a duplicate of https://bugs.openjdk.java.net/browse/JDK-8049898 since the latter bug is still open. This is in reality a duplicate of https://bugs.openjdk.java.net/browse/JDK-8047341 which is fixed in 9b22 and has also been already backported to 8u line.
01-06-2015

In my earlier attempt, I couldn't reproduce this - I'll investigate if this is a duplicate of JDK-8049898 or otherwise a duplicate of some other closed defect
16-03-2015

Checked this for following JDK versions: 8u25: FAIL 8u31: FAIL 8u40 b23: OK 9 b50: OK This looks like a duplicate of JDK-8049898 and resolved in JDK 8u40 and 9 builds.
24-02-2015