8074381: java.lang.AssertionError during compiling
authormcimadamore
Thu, 19 Mar 2015 11:39:36 +0000
changeset 29553 716d47f5a45e
parent 29552 690d0becaf32
child 29554 6d7957bd6866
8074381: java.lang.AssertionError during compiling Summary: Add extra functional interface check to prevent crash during code generation Reviewed-by: vromero
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/lambda/8074381/T8074381a.java
langtools/test/tools/javac/lambda/8074381/T8074381a.out
langtools/test/tools/javac/lambda/8074381/T8074381b.java
langtools/test/tools/javac/lambda/8074381/T8074381b.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Mar 13 10:25:46 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 19 11:39:36 2015 +0000
@@ -40,11 +40,13 @@
 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 @@
                             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();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8074381/T8074381a.java	Thu Mar 19 11:39:36 2015 +0000
@@ -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; }
+        };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8074381/T8074381a.out	Thu Mar 19 11:39:36 2015 +0000
@@ -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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8074381/T8074381b.java	Thu Mar 19 11:39:36 2015 +0000
@@ -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;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8074381/T8074381b.out	Thu Mar 19 11:39:36 2015 +0000
@@ -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