changeset 3054:700677b16a97

8139245: compiler crashes with exception on int:new method reference and generic method inference Reviewed-by: mcimadamore
author sadayapalam
date Mon, 12 Oct 2015 19:43:44 +0530
parents 79e637c1e083
children 814a0cab8c90
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out
diffstat 3 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Oct 12 12:24:33 2015 +0100
+++ b/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/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/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