changeset 3079:0caab0d65a04 jdk8u76-b01

8065986: Compiler fails to NullPointerException when calling super with Object<>() Summary: Missing POLY kind selector on recursive constructor calls with poly arguments Reviewed-by: vromero
author mcimadamore
date Thu, 12 Nov 2015 22:10:46 +0000
parents dcd12fa5b58a
children 78f0aa619915 bde967f54816
files src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/generics/diamond/8065986/T8065986a.java test/tools/javac/generics/diamond/8065986/T8065986a.out test/tools/javac/generics/diamond/8065986/T8065986b.java test/tools/javac/generics/diamond/8065986/T8065986b.out
diffstat 5 files changed, 84 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Nov 12 21:20:49 2015 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Nov 12 22:10:46 2015 +0000
@@ -662,8 +662,8 @@
 
     /** Attribute the arguments in a method call, returning the method kind.
      */
-    int attribArgs(List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) {
-        int kind = VAL;
+    int attribArgs(int initialKind, List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) {
+        int kind = initialKind;
         for (JCExpression arg : trees) {
             Type argtype;
             if (allowPoly && deferredAttr.isDeferred(env, arg)) {
@@ -1739,7 +1739,7 @@
                 localEnv.info.isSelfCall = true;
 
                 // Attribute arguments, yielding list of argument types.
-                attribArgs(tree.args, localEnv, argtypesBuf);
+                int kind = attribArgs(MTH, tree.args, localEnv, argtypesBuf);
                 argtypes = argtypesBuf.toList();
                 typeargtypes = attribTypes(tree.typeargs, localEnv);
 
@@ -1804,7 +1804,7 @@
                     // ...and check that it is legal in the current context.
                     // (this will also set the tree's type)
                     Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes);
-                    checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt));
+                    checkId(tree.meth, site, sym, localEnv, new ResultInfo(kind, mpt));
                 }
                 // Otherwise, `site' is an error type and we do nothing
             }
@@ -1812,7 +1812,7 @@
         } else {
             // Otherwise, we are seeing a regular method call.
             // Attribute the arguments, yielding list of argument types, ...
-            int kind = attribArgs(tree.args, localEnv, argtypesBuf);
+            int kind = attribArgs(VAL, tree.args, localEnv, argtypesBuf);
             argtypes = argtypesBuf.toList();
             typeargtypes = attribAnyTypes(tree.typeargs, localEnv);
 
@@ -1994,7 +1994,7 @@
 
         // Attribute constructor arguments.
         ListBuffer<Type> argtypesBuf = new ListBuffer<>();
-        int pkind = attribArgs(tree.args, localEnv, argtypesBuf);
+        int pkind = attribArgs(VAL, tree.args, localEnv, argtypesBuf);
         List<Type> argtypes = argtypesBuf.toList();
         List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/8065986/T8065986a.java	Thu Nov 12 22:10:46 2015 +0000
@@ -0,0 +1,33 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8065986
+ *
+ * @summary Compiler fails to NullPointerException when calling super with Object<>()
+ * @compile/fail/ref=T8065986a.out T8065986a.java -XDrawDiagnostics
+ *
+ */
+import java.util.ArrayList;
+
+class T8065986a {
+    T8065986a() {
+        super(new Object<>());
+    }
+
+    T8065986a(boolean b) {
+        super(new ArrayList<>());
+    }
+
+    T8065986a(boolean b1, boolean b2) {
+        super(()->{});
+    }
+
+    T8065986a(boolean b1, boolean b2, boolean b3) {
+        super(T8065986a::m);
+    }
+
+    T8065986a(boolean cond, Object o1, Object o2) {
+        super(cond ? o1 : o2);
+    }
+
+    static void m() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/8065986/T8065986a.out	Thu Nov 12 22:10:46 2015 +0000
@@ -0,0 +1,6 @@
+T8065986a.java:13:25: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object)
+T8065986a.java:17:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, java.util.ArrayList<java.lang.Object>, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch)
+T8065986a.java:21:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, @438, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch)
+T8065986a.java:25:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, @520, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch)
+T8065986a.java:29:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, @608, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch)
+5 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/8065986/T8065986b.java	Thu Nov 12 22:10:46 2015 +0000
@@ -0,0 +1,33 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8065986
+ *
+ * @summary Compiler fails to NullPointerException when calling super with Object<>()
+ * @compile/fail/ref=T8065986b.out T8065986b.java -XDrawDiagnostics
+ *
+ */
+import java.util.ArrayList;
+
+class T8065986b {
+    T8065986b() {
+        this(new Object<>());
+    }
+
+    T8065986b(boolean b) {
+        this(new ArrayList<>());
+    }
+
+    T8065986b(boolean b1, boolean b2) {
+        this(()->{});
+    }
+
+    T8065986b(boolean b1, boolean b2, boolean b3) {
+        this(T8065986b::m);
+    }
+
+    T8065986b(boolean cond, Object o1, Object o2) {
+        this(cond ? o1 : o2);
+    }
+
+    static void m() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/8065986/T8065986b.out	Thu Nov 12 22:10:46 2015 +0000
@@ -0,0 +1,6 @@
+T8065986b.java:13:24: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object)
+T8065986b.java:17:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, java.util.ArrayList<java.lang.Object>,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList<E>, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))}
+T8065986b.java:21:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @435,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))}
+T8065986b.java:25:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @516,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))}
+T8065986b.java:29:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @603,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: java.lang.Object, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))}
+5 errors