From 61d1dc59535a3dc186bc1986a04efdb4e5a8fa18 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Mon, 12 Aug 2024 13:52:57 +0000 Subject: [PATCH] 8334466: Ambiguous method call with generics may cause FunctionDescriptorLookupError Reviewed-by: jlahoda --- .../com/sun/tools/javac/comp/Resolve.java | 14 ++++++++--- ...WithFunctionDescriptorLookupErrorTest.java | 25 +++++++++++++++++++ ...hWithFunctionDescriptorLookupErrorTest.out | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.java create mode 100644 test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.out diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index c71b6d341dc..5bf1bc0ead1 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -1219,9 +1219,17 @@ public class Resolve { /** Parameters {@code t} and {@code s} are unrelated functional interface types. */ private boolean functionalInterfaceMostSpecific(Type t, Type s, JCTree tree) { - Type tDesc = types.findDescriptorType(types.capture(t)); - Type tDescNoCapture = types.findDescriptorType(t); - Type sDesc = types.findDescriptorType(s); + Type tDesc; + Type tDescNoCapture; + Type sDesc; + try { + tDesc = types.findDescriptorType(types.capture(t)); + tDescNoCapture = types.findDescriptorType(t); + sDesc = types.findDescriptorType(s); + } catch (Types.FunctionDescriptorLookupError ex) { + // don't report, a more meaningful error should be reported upstream + return false; + } final List tTypeParams = tDesc.getTypeArguments(); final List tTypeParamsNoCapture = tDescNoCapture.getTypeArguments(); final List sTypeParams = sDesc.getTypeArguments(); diff --git a/test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.java b/test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.java new file mode 100644 index 00000000000..bfdfc30609d --- /dev/null +++ b/test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.java @@ -0,0 +1,25 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8334466 + * @summary Ambiguous method call with generics may cause FunctionDescriptorLookupError + * @compile/fail/ref=CrashWithFunctionDescriptorLookupErrorTest.out -XDrawDiagnostics CrashWithFunctionDescriptorLookupErrorTest.java + */ + +import java.util.List; + +class CrashWithFunctionDescriptorLookupErrorTest { + void m() { + List list = List.of(new X()); + test(list.get(0)); + } + + void test(A a) { } + void test(B b) { } + + interface A> { T a(); } + interface B> { T b(); } + class X implements A, B { + public X a() { return null; } + public X b() { return null; } + } +} diff --git a/test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.out b/test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.out new file mode 100644 index 00000000000..06afbc8bc18 --- /dev/null +++ b/test/langtools/tools/javac/lambda/CrashWithFunctionDescriptorLookupErrorTest.out @@ -0,0 +1,2 @@ +CrashWithFunctionDescriptorLookupErrorTest.java:13:9: compiler.err.ref.ambiguous: test, kindname.method, test(CrashWithFunctionDescriptorLookupErrorTest.A), CrashWithFunctionDescriptorLookupErrorTest, kindname.method, test(CrashWithFunctionDescriptorLookupErrorTest.B), CrashWithFunctionDescriptorLookupErrorTest +1 error