Thu, 12 Nov 2015 22:10:46 +0000
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
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Nov 12 21:20:49 2015 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Nov 12 22:10:46 2015 +0000 1.3 @@ -662,8 +662,8 @@ 1.4 1.5 /** Attribute the arguments in a method call, returning the method kind. 1.6 */ 1.7 - int attribArgs(List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { 1.8 - int kind = VAL; 1.9 + int attribArgs(int initialKind, List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { 1.10 + int kind = initialKind; 1.11 for (JCExpression arg : trees) { 1.12 Type argtype; 1.13 if (allowPoly && deferredAttr.isDeferred(env, arg)) { 1.14 @@ -1739,7 +1739,7 @@ 1.15 localEnv.info.isSelfCall = true; 1.16 1.17 // Attribute arguments, yielding list of argument types. 1.18 - attribArgs(tree.args, localEnv, argtypesBuf); 1.19 + int kind = attribArgs(MTH, tree.args, localEnv, argtypesBuf); 1.20 argtypes = argtypesBuf.toList(); 1.21 typeargtypes = attribTypes(tree.typeargs, localEnv); 1.22 1.23 @@ -1804,7 +1804,7 @@ 1.24 // ...and check that it is legal in the current context. 1.25 // (this will also set the tree's type) 1.26 Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); 1.27 - checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt)); 1.28 + checkId(tree.meth, site, sym, localEnv, new ResultInfo(kind, mpt)); 1.29 } 1.30 // Otherwise, `site' is an error type and we do nothing 1.31 } 1.32 @@ -1812,7 +1812,7 @@ 1.33 } else { 1.34 // Otherwise, we are seeing a regular method call. 1.35 // Attribute the arguments, yielding list of argument types, ... 1.36 - int kind = attribArgs(tree.args, localEnv, argtypesBuf); 1.37 + int kind = attribArgs(VAL, tree.args, localEnv, argtypesBuf); 1.38 argtypes = argtypesBuf.toList(); 1.39 typeargtypes = attribAnyTypes(tree.typeargs, localEnv); 1.40 1.41 @@ -1994,7 +1994,7 @@ 1.42 1.43 // Attribute constructor arguments. 1.44 ListBuffer<Type> argtypesBuf = new ListBuffer<>(); 1.45 - int pkind = attribArgs(tree.args, localEnv, argtypesBuf); 1.46 + int pkind = attribArgs(VAL, tree.args, localEnv, argtypesBuf); 1.47 List<Type> argtypes = argtypesBuf.toList(); 1.48 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); 1.49
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/generics/diamond/8065986/T8065986a.java Thu Nov 12 22:10:46 2015 +0000 2.3 @@ -0,0 +1,33 @@ 2.4 +/* 2.5 + * @test /nodynamiccopyright/ 2.6 + * @bug 8065986 2.7 + * 2.8 + * @summary Compiler fails to NullPointerException when calling super with Object<>() 2.9 + * @compile/fail/ref=T8065986a.out T8065986a.java -XDrawDiagnostics 2.10 + * 2.11 + */ 2.12 +import java.util.ArrayList; 2.13 + 2.14 +class T8065986a { 2.15 + T8065986a() { 2.16 + super(new Object<>()); 2.17 + } 2.18 + 2.19 + T8065986a(boolean b) { 2.20 + super(new ArrayList<>()); 2.21 + } 2.22 + 2.23 + T8065986a(boolean b1, boolean b2) { 2.24 + super(()->{}); 2.25 + } 2.26 + 2.27 + T8065986a(boolean b1, boolean b2, boolean b3) { 2.28 + super(T8065986a::m); 2.29 + } 2.30 + 2.31 + T8065986a(boolean cond, Object o1, Object o2) { 2.32 + super(cond ? o1 : o2); 2.33 + } 2.34 + 2.35 + static void m() { } 2.36 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/generics/diamond/8065986/T8065986a.out Thu Nov 12 22:10:46 2015 +0000 3.3 @@ -0,0 +1,6 @@ 3.4 +T8065986a.java:13:25: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object) 3.5 +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) 3.6 +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) 3.7 +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) 3.8 +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) 3.9 +5 errors
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/generics/diamond/8065986/T8065986b.java Thu Nov 12 22:10:46 2015 +0000 4.3 @@ -0,0 +1,33 @@ 4.4 +/* 4.5 + * @test /nodynamiccopyright/ 4.6 + * @bug 8065986 4.7 + * 4.8 + * @summary Compiler fails to NullPointerException when calling super with Object<>() 4.9 + * @compile/fail/ref=T8065986b.out T8065986b.java -XDrawDiagnostics 4.10 + * 4.11 + */ 4.12 +import java.util.ArrayList; 4.13 + 4.14 +class T8065986b { 4.15 + T8065986b() { 4.16 + this(new Object<>()); 4.17 + } 4.18 + 4.19 + T8065986b(boolean b) { 4.20 + this(new ArrayList<>()); 4.21 + } 4.22 + 4.23 + T8065986b(boolean b1, boolean b2) { 4.24 + this(()->{}); 4.25 + } 4.26 + 4.27 + T8065986b(boolean b1, boolean b2, boolean b3) { 4.28 + this(T8065986b::m); 4.29 + } 4.30 + 4.31 + T8065986b(boolean cond, Object o1, Object o2) { 4.32 + this(cond ? o1 : o2); 4.33 + } 4.34 + 4.35 + static void m() { } 4.36 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/generics/diamond/8065986/T8065986b.out Thu Nov 12 22:10:46 2015 +0000 5.3 @@ -0,0 +1,6 @@ 5.4 +T8065986b.java:13:24: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object) 5.5 +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))} 5.6 +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))} 5.7 +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))} 5.8 +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.9 +5 errors