mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-16 10:53:31 +00:00
8074381: java.lang.AssertionError during compiling
Add extra functional interface check to prevent crash during code generation Reviewed-by: vromero
This commit is contained in:
parent
f1f1f0f7e1
commit
c03dd06d9a
@ -40,11 +40,13 @@ import com.sun.tools.javac.code.Lint.LintCategory;
|
||||
import com.sun.tools.javac.code.Scope.WriteableScope;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.code.Type.*;
|
||||
import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
|
||||
import com.sun.tools.javac.comp.Check.CheckContext;
|
||||
import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
|
||||
import com.sun.tools.javac.comp.Infer.InferenceContext;
|
||||
import com.sun.tools.javac.comp.Infer.FreeTypeListener;
|
||||
import com.sun.tools.javac.jvm.*;
|
||||
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
|
||||
import com.sun.tools.javac.tree.*;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*;
|
||||
@ -2871,6 +2873,16 @@ public class Attr extends JCTree.Visitor {
|
||||
names.empty, List.of(fExpr.targets.head), ABSTRACT);
|
||||
if (csym != null) {
|
||||
chk.checkImplementations(env.tree, csym, csym);
|
||||
try {
|
||||
//perform an additional functional interface check on the synthetic class,
|
||||
//as there may be spurious errors for raw targets - because of existing issues
|
||||
//with membership and inheritance (see JDK-8074570).
|
||||
csym.flags_field |= INTERFACE;
|
||||
types.findDescriptorType(csym.type);
|
||||
} catch (FunctionDescriptorLookupError err) {
|
||||
resultInfo.checkContext.report(fExpr,
|
||||
diags.fragment(Fragments.NoSuitableFunctionalIntfInst(fExpr.targets.head)));
|
||||
}
|
||||
}
|
||||
} catch (Types.FunctionDescriptorLookupError ex) {
|
||||
JCDiagnostic cause = ex.getDiagnostic();
|
||||
|
||||
33
langtools/test/tools/javac/lambda/8074381/T8074381a.java
Normal file
33
langtools/test/tools/javac/lambda/8074381/T8074381a.java
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8074381
|
||||
* @summary java.lang.AssertionError during compiling
|
||||
* @compile/fail/ref=T8074381a.out -XDrawDiagnostics T8074381a.java
|
||||
*/
|
||||
class T8074381a {
|
||||
interface Sup<X> {
|
||||
boolean m(X x);
|
||||
}
|
||||
|
||||
interface Sub<X> extends Sup<String> {
|
||||
boolean m(String s);
|
||||
}
|
||||
|
||||
void testRaw() {
|
||||
Sub s1 = c -> true;
|
||||
Sub s2 = Boolean::new;
|
||||
Sub s3 = new Sub() {
|
||||
@Override
|
||||
public boolean m(String o) { return true; }
|
||||
};
|
||||
}
|
||||
|
||||
void testNonRaw() {
|
||||
Sub<Integer> s1 = c -> true;
|
||||
Sub<Integer> s2 = Boolean::new;
|
||||
Sub<Integer> s3 = new Sub<Integer>() {
|
||||
@Override
|
||||
public boolean m(String o) { return true; }
|
||||
};
|
||||
}
|
||||
}
|
||||
4
langtools/test/tools/javac/lambda/8074381/T8074381a.out
Normal file
4
langtools/test/tools/javac/lambda/8074381/T8074381a.out
Normal file
@ -0,0 +1,4 @@
|
||||
T8074381a.java:17:18: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: T8074381a.Sub)
|
||||
T8074381a.java:18:18: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: T8074381a.Sub)
|
||||
T8074381a.java:19:28: compiler.err.does.not.override.abstract: compiler.misc.anonymous.class: T8074381a$1, m(java.lang.Object), T8074381a.Sup
|
||||
3 errors
|
||||
44
langtools/test/tools/javac/lambda/8074381/T8074381b.java
Normal file
44
langtools/test/tools/javac/lambda/8074381/T8074381b.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8074381
|
||||
* @summary java.lang.AssertionError during compiling
|
||||
* @compile/fail/ref=T8074381b.out -XDrawDiagnostics T8074381b.java
|
||||
*/
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class T8074381b {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Invocation resolve(Handler handler) {
|
||||
return new Invocation((t) -> handler.handle((String) t));
|
||||
}
|
||||
|
||||
public static class Handler {
|
||||
public void handle(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Invocation<T> {
|
||||
public final ThrowingConsumer<T> consumer;
|
||||
|
||||
public Invocation(final ThrowingConsumer<T> consumer) {
|
||||
this.consumer = consumer;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ThrowingConsumer<T> extends BiConsumer<T,Consumer<Throwable>> {
|
||||
@Override
|
||||
default void accept(final T elem, final Consumer<Throwable> errorHandler) {
|
||||
try {
|
||||
acceptThrows(elem);
|
||||
} catch (final Throwable e) {
|
||||
errorHandler.accept(e);
|
||||
}
|
||||
}
|
||||
|
||||
void acceptThrows(T elem) throws Throwable;
|
||||
}
|
||||
}
|
||||
2
langtools/test/tools/javac/lambda/8074381/T8074381b.out
Normal file
2
langtools/test/tools/javac/lambda/8074381/T8074381b.out
Normal file
@ -0,0 +1,2 @@
|
||||
T8074381b.java:14:16: compiler.err.cant.apply.symbol: kindname.constructor, Invocation, T8074381b.ThrowingConsumer, @383, kindname.class, T8074381b.Invocation<T>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.no.suitable.functional.intf.inst: T8074381b.ThrowingConsumer))
|
||||
1 error
|
||||
Loading…
x
Reference in New Issue
Block a user