mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
Co-authored-by: Maurizio Cimadamore <maurizio.cimadamore@oracle.com> Reviewed-by: mcimadamore
This commit is contained in:
parent
17f9ae5713
commit
5b199f3cb8
4 changed files with 40 additions and 5 deletions
|
@ -626,7 +626,7 @@ public class Types {
|
||||||
* (ii) perform functional interface bridge calculation.
|
* (ii) perform functional interface bridge calculation.
|
||||||
*/
|
*/
|
||||||
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
|
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
|
||||||
if (targets.isEmpty() || !isFunctionalInterface(targets.head)) {
|
if (targets.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
|
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
|
||||||
|
|
|
@ -3135,11 +3135,20 @@ public class Attr extends JCTree.Visitor {
|
||||||
if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
|
if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
|
||||||
pt != Type.recoveryType) {
|
pt != Type.recoveryType) {
|
||||||
//check that functional interface class is well-formed
|
//check that functional interface class is well-formed
|
||||||
|
try {
|
||||||
|
/* Types.makeFunctionalInterfaceClass() may throw an exception
|
||||||
|
* when it's executed post-inference. See the listener code
|
||||||
|
* above.
|
||||||
|
*/
|
||||||
ClassSymbol csym = types.makeFunctionalInterfaceClass(env,
|
ClassSymbol csym = types.makeFunctionalInterfaceClass(env,
|
||||||
names.empty, List.of(fExpr.targets.head), ABSTRACT);
|
names.empty, List.of(fExpr.targets.head), ABSTRACT);
|
||||||
if (csym != null) {
|
if (csym != null) {
|
||||||
chk.checkImplementations(env.tree, csym, csym);
|
chk.checkImplementations(env.tree, csym, csym);
|
||||||
}
|
}
|
||||||
|
} catch (Types.FunctionDescriptorLookupError ex) {
|
||||||
|
JCDiagnostic cause = ex.getDiagnostic();
|
||||||
|
resultInfo.checkContext.report(env.tree, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8038182
|
||||||
|
* @summary javac crash with FunctionDescriptorLookupError for invalid functional interface
|
||||||
|
* @compile/fail/ref=CrashFunctionDescriptorExceptionTest.out -XDrawDiagnostics CrashFunctionDescriptorExceptionTest.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CrashFunctionDescriptorExceptionTest {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void m () {
|
||||||
|
bar((B b) -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
<E extends A<E>> void bar(I<E> i) {}
|
||||||
|
|
||||||
|
class A<E> {}
|
||||||
|
|
||||||
|
class B<E> extends A<E> {}
|
||||||
|
|
||||||
|
interface I<E extends A<E>> {
|
||||||
|
void foo(E e);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
CrashFunctionDescriptorExceptionTest.java:12:13: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: CrashFunctionDescriptorExceptionTest.I<CrashFunctionDescriptorExceptionTest.B>)
|
||||||
|
1 error
|
Loading…
Add table
Add a link
Reference in a new issue