JDK-8269983 : BootstrapMethodError with method reference and intersection type
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 11,17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-07-06
  • Updated: 2022-10-13
  • Resolved: 2022-10-07
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 20
20 b19Fixed
Related Reports
Relates :  
Description
Under JDK 8, the following program compiles and runs successfully.

Under JDK 11 and newer, it fails at runtime with a BootstrapMethodError.

I'd expect it to either be rejected by javac at compile-time, or succeed at runtime, but not compile and then fail at runtime.

This may be related to JDK-8269020, although that issue can be worked around by expressing the intersection bounds consistent, which doesn't apply to the following repro.

public class Z {

  public static void main(String[] args) {
    f();
  }

  static <T extends Comparable<T> & G> C<T> f() {
    return new C<>(Q::g);
  }

  public interface G {}

  private interface E<T> {
    void g(Q g, T value);
  }

  static class C<T extends Comparable<?>> {
    C(E<T> g) {}
  }

  static class Q {
    void g(G g) {}
  }
}

Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
	at Z.f(Z.java:9)
	at Z.main(Z.java:5)
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument 1: interface java.lang.Comparable is not convertible to interface Z$G
	at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:279)
	at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:328)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:127)
	... 5 more
Comments
Changeset: cf84c8ea Author: Srikanth Adayapalam <sadayapalam@openjdk.org> Date: 2022-10-07 04:20:40 +0000 URL: https://git.openjdk.org/jdk/commit/cf84c8eaf265255b49293650b3919f22e26d48a3
07-10-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10548 Date: 2022-10-04 06:09:10 +0000
04-10-2022

I have a candidate fix for JDK-8292975 which also seems to address this.
03-10-2022

The regression bisects to JDK-8213703
07-07-2021