Skip to content

Commit 61d1dc5

Browse files
author
Vicente Romero
committed
8334466: Ambiguous method call with generics may cause FunctionDescriptorLookupError
Reviewed-by: jlahoda
1 parent 89a15f1 commit 61d1dc5

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,17 @@ private boolean unrelatedInterfaces(Type t, Type s) {
12191219

12201220
/** Parameters {@code t} and {@code s} are unrelated functional interface types. */
12211221
private boolean functionalInterfaceMostSpecific(Type t, Type s, JCTree tree) {
1222-
Type tDesc = types.findDescriptorType(types.capture(t));
1223-
Type tDescNoCapture = types.findDescriptorType(t);
1224-
Type sDesc = types.findDescriptorType(s);
1222+
Type tDesc;
1223+
Type tDescNoCapture;
1224+
Type sDesc;
1225+
try {
1226+
tDesc = types.findDescriptorType(types.capture(t));
1227+
tDescNoCapture = types.findDescriptorType(t);
1228+
sDesc = types.findDescriptorType(s);
1229+
} catch (Types.FunctionDescriptorLookupError ex) {
1230+
// don't report, a more meaningful error should be reported upstream
1231+
return false;
1232+
}
12251233
final List<Type> tTypeParams = tDesc.getTypeArguments();
12261234
final List<Type> tTypeParamsNoCapture = tDescNoCapture.getTypeArguments();
12271235
final List<Type> sTypeParams = sDesc.getTypeArguments();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @test /nodynamiccopyright/
3+
* @bug 8334466
4+
* @summary Ambiguous method call with generics may cause FunctionDescriptorLookupError
5+
* @compile/fail/ref=CrashWithFunctionDescriptorLookupErrorTest.out -XDrawDiagnostics CrashWithFunctionDescriptorLookupErrorTest.java
6+
*/
7+
8+
import java.util.List;
9+
10+
class CrashWithFunctionDescriptorLookupErrorTest {
11+
void m() {
12+
List<X> list = List.of(new X());
13+
test(list.get(0));
14+
}
15+
16+
void test(A<?> a) { }
17+
void test(B<?> b) { }
18+
19+
interface A<T extends A<T>> { T a(); }
20+
interface B<T extends B<T>> { T b(); }
21+
class X implements A<X>, B<X> {
22+
public X a() { return null; }
23+
public X b() { return null; }
24+
}
25+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CrashWithFunctionDescriptorLookupErrorTest.java:13:9: compiler.err.ref.ambiguous: test, kindname.method, test(CrashWithFunctionDescriptorLookupErrorTest.A<?>), CrashWithFunctionDescriptorLookupErrorTest, kindname.method, test(CrashWithFunctionDescriptorLookupErrorTest.B<?>), CrashWithFunctionDescriptorLookupErrorTest
2+
1 error

0 commit comments

Comments
 (0)