From ac4f8dfdd2ef30ad09d4f9906c1fd559820a3221 Mon Sep 17 00:00:00 2001 From: Srikanth Adayapalam Date: Mon, 12 Oct 2015 19:43:44 +0530 Subject: [PATCH] 8139245: compiler crashes with exception on int:new method reference and generic method inference Reviewed-by: mcimadamore --- .../com/sun/tools/javac/comp/Resolve.java | 12 ++++++----- .../MethodRefIntColonColonNewTest.java | 20 +++++++++++++++++++ .../MethodRefIntColonColonNewTest.out | 3 +++ 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java create mode 100644 langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index e572778d487..7aef1258415 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -3215,8 +3215,7 @@ public class Resolve { 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 @@ public class Resolve { } } - boolean hasEnclosingInstance(Env env, Type type) { - Symbol encl = resolveSelfContainingInternal(env, type.tsym, false); - return encl != null && !encl.kind.isResolutionError(); + boolean enclosingInstanceMissing(Env 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 env, diff --git a/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java b/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java new file mode 100644 index 00000000000..61cd10b4dc7 --- /dev/null +++ b/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.java @@ -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 m(T s); + } + + static SAM infmethod(SAM t) { return t; } + + public static void main(String argv[]) { + SAM s = infmethod(int::new); + s.m(); + } +} diff --git a/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out b/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out new file mode 100644 index 00000000000..83fd752c75f --- /dev/null +++ b/langtools/test/tools/javac/lambda/methodReference/MethodRefIntColonColonNewTest.out @@ -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, (compiler.misc.arg.length.mismatch) +2 errors