JDK-8213032 : program fails with LambdaConversionException at execution time
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-10-26
  • Updated: 2021-01-20
  • Resolved: 2021-01-05
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 16 JDK 17
16 b31Fixed 17Fixed
Related Reports
Relates :  
Description
this program:

import java.util.stream.*;

public class Test {
  interface  I {}
  static abstract class C { }
  static class A extends C implements I { }
  static class B extends C implements I { }

  static String f(I i) { return null; }

  public static void main(String[] args) {
    Stream.of(new A(), new B())
      .map(Test::f)
      .forEach(System.out::println);
  }
}

is accepted by the compiler but fails with LCE at execution time. Reported at: http://mail.openjdk.java.net/pipermail/compiler-dev/2018-October/012569.html
Comments
Changeset: d5293067 Author: Vicente Romero <vromero@openjdk.org> Date: 2021-01-05 21:35:47 +0000 URL: https://git.openjdk.java.net/jdk16/commit/d5293067
05-01-2021

Another example along with an experimental fix: http://mail.openjdk.java.net/pipermail/compiler-dev/2020-December/015942.html
28-12-2020

I stumble on this very same bug yesterday https://mail.openjdk.java.net/pipermail/amber-dev/2020-November/006818.html still not fixed :(
17-11-2020

Related thread: http://mail.openjdk.java.net/pipermail/compiler-dev/2020-October/015185.html
20-10-2020

Potential fix on jdk14u (langtools:tier1 is OK): diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java @@ -968,6 +968,10 @@ // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type + if (checkForIntersection && descPTypes.head.getKind() == TypeKind.INTERSECTION) { + parmType = samPTypes.head; + } + if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.getUpperBound().getKind() == TypeKind.INTERSECTION) {
14-10-2020