changeset 1795:5da12e8a59ba

8010387: Javac crashes when diagnostic mentions anonymous inner class' type variables Summary: Rich formatter doesn't preprocess supertypes of an anonymous inner class Reviewed-by: jjg
author mcimadamore
date Fri, 22 Mar 2013 12:44:48 +0000
parents c6728c9addff
children f4500abff1fd
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	Fri Mar 22 12:43:09 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Fri Mar 22 12:44:48 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	Fri Mar 22 12:44:48 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	Fri Mar 22 12:44:48 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