changeset 1904:b80c4f8b1329

JDK-8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables
author mcimadamore
date Wed, 20 Mar 2013 12:45:50 +0000
parents 0813ec17c531
children 85ba5a25c9e2
files src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java test/tools/javac/Diagnostics/8010387/T8010387.java test/tools/javac/Diagnostics/8010387/T8010387.out
diffstat 3 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Tue Mar 19 17:20:50 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Wed Mar 20 12:45:50 2013 +0000
@@ -509,6 +509,16 @@
                     visit(supertype);
                     visit(interfaces);
                 }
+            } else if (t.tsym.name.isEmpty()) {
+                //anon class
+                ClassType norm = (ClassType) t.tsym.type;
+                if (norm != null) {
+                    if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
+                        visit(norm.interfaces_field.head);
+                    } else {
+                        visit(norm.supertype_field);
+                    }
+                }
             }
             nameSimplifier.addUsage(t.tsym);
             visit(t.getTypeArguments());
@@ -562,7 +572,7 @@
     // <editor-fold defaultstate="collapsed" desc="symbol scanner">
     /**
      * Preprocess a given symbol looking for (i) additional info (where clauses) to be
-     * asdded to the main diagnostic (ii) names to be compacted
+     * added to the main diagnostic (ii) names to be compacted
      */
     protected void preprocessSymbol(Symbol s) {
         symbolPreprocessor.visit(s, null);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/8010387/T8010387.java	Wed Mar 20 12:45:50 2013 +0000
@@ -0,0 +1,17 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug     8010387
+ * @summary rich diagnostic sometimes contain wrong type variable numbering
+ * @compile/fail/ref=T8010387.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T8010387.java
+ */
+abstract class T8010387<X> {
+    
+    interface F<X> { }
+
+    <P> void test() {
+        m(new F<P>() { });
+    }
+
+
+    abstract <T> T8010387<?> m(F<? extends X> fx);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/8010387/T8010387.out	Wed Mar 20 12:45:50 2013 +0000
@@ -0,0 +1,3 @@
+T8010387.java:12:9: compiler.err.cant.apply.symbol: kindname.method, m, T8010387.F<? extends X>, compiler.misc.anonymous.class: T8010387.F<P>, kindname.class, T8010387<X>, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: T8010387.F<P>, T8010387.F<? extends X>))
+- compiler.misc.where.description.typevar.1: X,P,T,{(compiler.misc.where.typevar: X, java.lang.Object, kindname.class, T8010387),(compiler.misc.where.typevar: P, java.lang.Object, kindname.method, <P>test()),(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>m(T8010387.F<? extends X>))}
+1 error