changeset 1705:3abe676095c6

Fix: uncatched sam conversion failure exception lead to javac crash
author mcimadamore
date Wed, 19 Dec 2012 18:33:34 +0000
parents b11f5172a066
children 1faa2226c00e
files src/share/classes/com/sun/tools/javac/code/Types.java src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java test/tools/javac/lambda/TargetType52.java test/tools/javac/lambda/TargetType52.out
diffstat 4 files changed, 51 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Dec 17 18:51:05 2012 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Dec 19 18:33:34 2012 +0000
@@ -574,6 +574,15 @@
             return false;
         }
     }
+    
+    public boolean isFunctionalInterface(Type site) {
+        try {
+            findDescriptorType(site);
+            return true;
+        } catch (FunctionDescriptorLookupError ex) {
+            return false;
+        }
+    }
     // </editor-fold>
 
    /**
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Mon Dec 17 18:51:05 2012 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed Dec 19 18:33:34 2012 +0000
@@ -454,9 +454,13 @@
                         return;
                     } else {
                         //must be a functional descriptor
-                        Type desc = types.findDescriptorType(pt);
-                        if (desc.getParameterTypes().length() != tree.params.length()) {
-                            checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda"));
+                        try {
+                            Type desc = types.findDescriptorType(pt);
+                            if (desc.getParameterTypes().length() != tree.params.length()) {
+                                checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda"));
+                            }
+                        } catch (Types.FunctionDescriptorLookupError ex) {
+                            checkContext.report(null, ex.getDiagnostic());
                         }
                     }
                 }
@@ -473,8 +477,20 @@
 
                 @Override
                 public void visitReference(JCMemberReference tree) {
-                    //TODO: we should speculative determine if there's a match
-                    //based on arity - if yes, method is applicable.
+                    Check.CheckContext checkContext = resultInfo.checkContext;
+                    Type pt = resultInfo.pt;
+                    if (inferenceContext.inferencevars.contains(pt)) {
+                        //ok
+                        return;
+                    } else {
+                        try {
+                            //TODO: we should speculative determine if there's a match
+                            //based on arity - if yes, method is applicable.
+                            types.findDescriptorType(pt);
+                        } catch (Types.FunctionDescriptorLookupError ex) {
+                            checkContext.report(null, ex.getDiagnostic());
+                        }
+                    }
                 }
             }
         }
@@ -681,7 +697,7 @@
             if (inferenceContext.inferenceVars().contains(pt)) {
                 stuckVars.add(pt);
             }
-            if (!types.isFunctionalInterface(pt.tsym)) {
+            if (!types.isFunctionalInterface(pt)) {
                 return;
             }
             Type descType = types.findDescriptorType(pt);
@@ -700,7 +716,7 @@
                 stuckVars.add(pt);
                 return;
             }
-            if (!types.isFunctionalInterface(pt.tsym)) {
+            if (!types.isFunctionalInterface(pt)) {
                 return;
             }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/TargetType52.java	Wed Dec 19 18:33:34 2012 +0000
@@ -0,0 +1,17 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary uncatched sam conversion failure exception lead to javac crash
+ * @compile/fail/ref=TargetType52.out -XDrawDiagnostics TargetType52.java
+ */
+class TargetType52 {
+
+    interface FI<T extends CharSequence, V extends java.util.AbstractList<T>> {
+        T m(V p); 
+    }
+
+    void m(FI<? extends CharSequence, ? extends java.util.ArrayList<? extends CharSequence>> fip) { }
+    
+    void test() {
+        m(p -> p.get(0)); 
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/TargetType52.out	Wed Dec 19 18:33:34 2012 +0000
@@ -0,0 +1,2 @@
+TargetType52.java:15:9: compiler.err.cant.apply.symbol: kindname.method, m, TargetType52.FI<? extends java.lang.CharSequence,? extends java.util.ArrayList<? extends java.lang.CharSequence>>, @449, kindname.class, TargetType52, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.no.suitable.functional.intf.inst: TargetType52.FI<java.lang.CharSequence,java.util.ArrayList<? extends java.lang.CharSequence>>))
+1 error