changeset 2655:a12a9932f649 jdk8u40-b17

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
author jlahoda
date Mon, 22 Sep 2014 14:55:14 +0200
parents 4721674bb051
children feafeed79979 94f30e5fde53
files src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/lambda/T8057794.java test/tools/javac/lambda/T8057794.out
diffstat 3 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Nov 26 13:59:04 2014 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Sep 22 14:55:14 2014 +0200
@@ -3226,8 +3226,9 @@
                 elt = ((ArrayType)elt.unannotatedType()).elemtype;
             if (elt.hasTag(TYPEVAR)) {
                 log.error(tree.pos(), "type.var.cant.be.deref");
-                result = types.createErrorType(tree.type);
-                return;
+                result = tree.type = types.createErrorType(tree.name, site.tsym, site);
+                tree.sym = tree.type.tsym;
+                return ;
             }
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8057794.java	Mon Sep 22 14:55:14 2014 +0200
@@ -0,0 +1,12 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     8057794
+ * @summary The tree for TypeVar.class does not have a type set, which leads to an NPE when
+ *          checking if deferred attribution is needed
+ * @compile/fail/ref=T8057794.out -XDrawDiagnostics T8057794.java
+ */
+class T8057794<T> {
+    void t() {
+        System.out.println(T.class.getSimpleName());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8057794.out	Mon Sep 22 14:55:14 2014 +0200
@@ -0,0 +1,2 @@
+T8057794.java:10:29: compiler.err.type.var.cant.be.deref
+1 error