提交 a6c49767 编写于 作者: V vromero

8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface

Reviewed-by: mcimadamore
Contributed-by: maurizio.cimadamore@oracle.com, vicente.romero@oracle.com
上级 a7fc656c
......@@ -629,7 +629,7 @@ public class Types {
* (ii) perform functional interface bridge calculation.
*/
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
if (targets.isEmpty() || !isFunctionalInterface(targets.head)) {
if (targets.isEmpty()) {
return null;
}
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
......
......@@ -2968,10 +2968,19 @@ public class Attr extends JCTree.Visitor {
if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
pt != Type.recoveryType) {
//check that functional interface class is well-formed
ClassSymbol csym = types.makeFunctionalInterfaceClass(env,
names.empty, List.of(fExpr.targets.head), ABSTRACT);
if (csym != null) {
chk.checkImplementations(env.tree, csym, csym);
try {
/* Types.makeFunctionalInterfaceClass() may throw an exception
* when it's executed post-inference. See the listener code
* above.
*/
ClassSymbol csym = types.makeFunctionalInterfaceClass(env,
names.empty, List.of(fExpr.targets.head), ABSTRACT);
if (csym != null) {
chk.checkImplementations(env.tree, csym, csym);
}
} catch (Types.FunctionDescriptorLookupError ex) {
JCDiagnostic cause = ex.getDiagnostic();
resultInfo.checkContext.report(env.tree, cause);
}
}
}
......
/*
* @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);
}
}
CrashFunctionDescriptorExceptionTest.java:12:13: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: CrashFunctionDescriptorExceptionTest.I<CrashFunctionDescriptorExceptionTest.B>)
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册