Mon, 22 Sep 2014 14:55:14 +0200
8057794: Compiler Error when obtaining .class property
Summary: Ensuring a non-null type and sym for illegal T.class to prevent downstream errors.
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Nov 26 13:59:04 2014 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Sep 22 14:55:14 2014 +0200 1.3 @@ -3226,8 +3226,9 @@ 1.4 elt = ((ArrayType)elt.unannotatedType()).elemtype; 1.5 if (elt.hasTag(TYPEVAR)) { 1.6 log.error(tree.pos(), "type.var.cant.be.deref"); 1.7 - result = types.createErrorType(tree.type); 1.8 - return; 1.9 + result = tree.type = types.createErrorType(tree.name, site.tsym, site); 1.10 + tree.sym = tree.type.tsym; 1.11 + return ; 1.12 } 1.13 } 1.14
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/lambda/T8057794.java Mon Sep 22 14:55:14 2014 +0200 2.3 @@ -0,0 +1,12 @@ 2.4 +/** 2.5 + * @test /nodynamiccopyright/ 2.6 + * @bug 8057794 2.7 + * @summary The tree for TypeVar.class does not have a type set, which leads to an NPE when 2.8 + * checking if deferred attribution is needed 2.9 + * @compile/fail/ref=T8057794.out -XDrawDiagnostics T8057794.java 2.10 + */ 2.11 +class T8057794<T> { 2.12 + void t() { 2.13 + System.out.println(T.class.getSimpleName()); 2.14 + } 2.15 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/lambda/T8057794.out Mon Sep 22 14:55:14 2014 +0200 3.3 @@ -0,0 +1,2 @@ 3.4 +T8057794.java:10:29: compiler.err.type.var.cant.be.deref 3.5 +1 error