8139245: compiler crashes with exception on int:new method reference and generic method inference
authorsadayapalam
Mon, 12 Oct 2015 19:43:44 +0530
changeset 33019 2dc64d1f5e18
parent 33018 9790ed482dd0
child 33020 7ed4f7ff42c5
8139245: compiler crashes with exception on int:new method reference and generic method inference Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java
langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Oct 12 12:24:33 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Oct 12 19:43:44 2015 +0530
@@ -3215,8 +3215,7 @@
                 findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) :
                 findMethod(env, site, name, argtypes, typeargtypes,
                         phase.isBoxingRequired(), phase.isVarargsRequired());
-            return site.getEnclosingType().hasTag(CLASS) && !hasEnclosingInstance(env, site) ?
-                        new BadConstructorReferenceError(sym) : sym;
+            return enclosingInstanceMissing(env, site) ? new BadConstructorReferenceError(sym) : sym;
         }
 
         @Override
@@ -3349,9 +3348,12 @@
         }
     }
 
-    boolean hasEnclosingInstance(Env<AttrContext> env, Type type) {
-        Symbol encl = resolveSelfContainingInternal(env, type.tsym, false);
-        return encl != null && !encl.kind.isResolutionError();
+    boolean enclosingInstanceMissing(Env<AttrContext> env, Type type) {
+        if (type.hasTag(CLASS) && type.getEnclosingType().hasTag(CLASS)) {
+            Symbol encl = resolveSelfContainingInternal(env, type.tsym, false);
+            return encl == null || encl.kind.isResolutionError();
+        }
+        return false;
     }
 
     private Symbol resolveSelfContainingInternal(Env<AttrContext> env,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java	Mon Oct 12 19:43:44 2015 +0530
@@ -0,0 +1,20 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     8139245
+ * @summary compiler crashes with exception on int:new method reference and generic method inference
+ * @compile/fail/ref=MethodRefIntColonColonNewTest.out -XDrawDiagnostics MethodRefIntColonColonNewTest.java
+ */
+
+public class MethodRefIntColonColonNewTest {
+
+    interface SAM<T> {
+        T m(T s);
+    }
+
+    static <T> SAM<T> infmethod(SAM<T> t) { return t; }
+
+    public static void main(String argv[]) {
+        SAM<Object> s = infmethod(int::new);
+        s.m();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out	Mon Oct 12 19:43:44 2015 +0530
@@ -0,0 +1,3 @@
+MethodRefIntColonColonNewTest.java:17:35: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
+MethodRefIntColonColonNewTest.java:18:10: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Object, compiler.misc.no.args, kindname.interface, MethodRefIntColonColonNewTest.SAM<T>, (compiler.misc.arg.length.mismatch)
+2 errors