8057794: Compiler Error when obtaining .class property
Ensuring a non-null type and sym for illegal T.class to prevent downstream errors.
Reviewed-by: mcimadamore
diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
index dfd9978..1a25a74 100644
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
@@ -3195,8 +3195,9 @@
elt = ((ArrayType)elt).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 ;
}
}
diff --git a/langtools/test/tools/javac/lambda/T8057794.java b/langtools/test/tools/javac/lambda/T8057794.java
new file mode 100644
index 0000000..2bf4c5a
--- /dev/null
+++ b/langtools/test/tools/javac/lambda/T8057794.java
@@ -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());
+ }
+}
diff --git a/langtools/test/tools/javac/lambda/T8057794.out b/langtools/test/tools/javac/lambda/T8057794.out
new file mode 100644
index 0000000..fa025a9
--- /dev/null
+++ b/langtools/test/tools/javac/lambda/T8057794.out
@@ -0,0 +1,2 @@
+T8057794.java:10:29: compiler.err.type.var.cant.be.deref
+1 error