JDK-8322810 : Lambda expression types can't be classes
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 11,17,21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2023-12-23
  • Updated: 2025-05-13
  • Resolved: 2025-05-02
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 25
25 b22Fixed
Related Reports
CSR :  
Causes :  
Relates :  
Sub Tasks
JDK-8356106 :  
Description
ADDITIONAL SYSTEM INFORMATION :
Tested on JDK 17, 21 and 22

A DESCRIPTION OF THE PROBLEM :
javac can compile lambda expressions assigned to intersection types, even if one of the types is a class, not an interface. This frequently leads to bytecode being generated that raises a LambdaConversionException when executed. It is also possible to generate bytecode that fails verification and throws a VerifyError. I'm not fully sure why the latter case occurs, but I assume that a lambda implementing a class breaks some assumptions in other components in the compiler which results in bytecode that fails verification.

This appears to be a regression, as javac refuses to compile this code in Java 8, but by Java 11 it compiles.

REGRESSION : Last worked in version 8u391

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Download the test case
2. Compile it with javac
3. Observe it compiles successfully with no errors or warnings.
4. Run Main for the LambdaConversionException, and run MainVerifyError for the VerifyError.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Lambdas cannot implement classes and a compile error is raised.
ACTUAL -
Code compiles successfully and fails at runtime with a LambdaConversionException, or sometimes a VerifyError.

---------- BEGIN SOURCE ----------
public class Main {
  public static void main(String[] args) {
    var r = (Main & Runnable) () -> System.out.println("Hello, World!");
  }
}

class MainVerifyError {
  public static void main(String[] args) {
    run(() -> System.out.println("Hello, World!"));
  }

  static <T extends MainVerifyError & Runnable> void run(T t) {
    t.run();
  }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Changeset: 56468c42 Branch: master Author: Vicente Romero <vromero@openjdk.org> Date: 2025-05-02 20:44:22 +0000 URL: https://git.openjdk.org/jdk/commit/56468c42bef8524e53a929dc2ae603cff05b55e3
02-05-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/24548 Date: 2025-04-09 14:03:03 +0000
09-04-2025

bug caused by: JDK-8148354
08-04-2025

The submitter says it last worked in JDK 8u391. The reproducer uses var keyword. It cannot be used in JDK 8. Removing the regression label
02-01-2024

The issue is reproducible since JDK 11: PS C:\test> C:\jdk\jdk-11.0.20+9_windows-x64_bin\jdk-11.0.20\bin\java Main 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 Main.main(Main.java:3) Caused by: java.lang.invoke.LambdaConversionException: Marker interface Main is not an interface at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.<init>(AbstractValidatingLambdaMetafactory.java:185) at java.base/java.lang.invoke.InnerClassLambdaMetafactory.<init>(InnerClassLambdaMetafactory.java:158) at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:496) at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138) ... 4 more PS C:\test> C:\jdk\openjdk-22-ea+16_windows-x64_bin\jdk-22\bin\javac Main.java PS C:\test> C:\jdk\openjdk-22-ea+16_windows-x64_bin\jdk-22\bin\java Main Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188) at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:316) at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:275) at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:265) at Main.main(Main.java:3) Caused by: java.lang.invoke.LambdaConversionException: Main is not an interface at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.<init>(AbstractValidatingLambdaMetafactory.java:204) at java.base/java.lang.invoke.InnerClassLambdaMetafactory.<init>(InnerClassLambdaMetafactory.java:168) at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:525) at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:147) ... 4 more
02-01-2024