8073616: Duplicate error message: cannot inherit from final (class) F
authorsadayapalam
Fri, 13 Nov 2015 18:09:36 +0530
changeset 33907 9ee2b1641949
parent 33906 91b6bee06dc1
child 33908 15817ee63d11
child 33912 41d8938af3fc
8073616: Duplicate error message: cannot inherit from final (class) F Summary: Ensure that the compiler does not emit duplicate errors at slightly different source positions. Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/generics/CheckNoDuplicateErrors.java
langtools/test/tools/javac/generics/CheckNoDuplicateErrors.out
langtools/test/tools/javac/lambda/TargetType68.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Nov 13 12:29:23 2015 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Nov 13 18:09:36 2015 +0530
@@ -840,8 +840,10 @@
                    boolean classExpected,
                    boolean interfaceExpected,
                    boolean checkExtensible) {
+        final DiagnosticPosition pos = tree.hasTag(TYPEAPPLY) ?
+                (((JCTypeApply) tree).clazz).pos() : tree.pos();
         if (t.tsym.isAnonymous()) {
-            log.error(tree.pos(), "cant.inherit.from.anon");
+            log.error(pos, "cant.inherit.from.anon");
             return types.createErrorType(t);
         }
         if (t.isErroneous())
@@ -849,29 +851,29 @@
         if (t.hasTag(TYPEVAR) && !classExpected && !interfaceExpected) {
             // check that type variable is already visible
             if (t.getUpperBound() == null) {
-                log.error(tree.pos(), "illegal.forward.ref");
+                log.error(pos, "illegal.forward.ref");
                 return types.createErrorType(t);
             }
         } else {
-            t = chk.checkClassType(tree.pos(), t, checkExtensible);
+            t = chk.checkClassType(pos, t, checkExtensible);
         }
         if (interfaceExpected && (t.tsym.flags() & INTERFACE) == 0) {
-            log.error(tree.pos(), "intf.expected.here");
+            log.error(pos, "intf.expected.here");
             // return errType is necessary since otherwise there might
             // be undetected cycles which cause attribution to loop
             return types.createErrorType(t);
         } else if (checkExtensible &&
                    classExpected &&
                    (t.tsym.flags() & INTERFACE) != 0) {
-            log.error(tree.pos(), "no.intf.expected.here");
+            log.error(pos, "no.intf.expected.here");
             return types.createErrorType(t);
         }
         if (checkExtensible &&
             ((t.tsym.flags() & FINAL) != 0)) {
-            log.error(tree.pos(),
+            log.error(pos,
                       "cant.inherit.from.final", t.tsym);
         }
-        chk.checkNonCyclic(tree.pos(), t);
+        chk.checkNonCyclic(pos, t);
         return t;
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/CheckNoDuplicateErrors.java	Fri Nov 13 18:09:36 2015 +0530
@@ -0,0 +1,16 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8073616
+ * @summary Ensure compiler does not emit duplicate error messages at slightly different source positions
+ *
+ * @compile/fail/ref=CheckNoDuplicateErrors.out -XDrawDiagnostics CheckNoDuplicateErrors.java
+ */
+
+import java.util.ArrayList;
+
+final class CheckNoDuplicateErrors_01<T> {}
+
+public class CheckNoDuplicateErrors extends CheckNoDuplicateErrors_01<String>
+                                    implements ArrayList<String> {
+    CheckNoDuplicateErrors_01 f = new CheckNoDuplicateErrors_01<String> () { };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/CheckNoDuplicateErrors.out	Fri Nov 13 18:09:36 2015 +0530
@@ -0,0 +1,4 @@
+CheckNoDuplicateErrors.java:13:45: compiler.err.cant.inherit.from.final: CheckNoDuplicateErrors_01
+CheckNoDuplicateErrors.java:14:48: compiler.err.intf.expected.here
+CheckNoDuplicateErrors.java:15:39: compiler.err.cant.inherit.from.final: CheckNoDuplicateErrors_01
+3 errors
--- a/langtools/test/tools/javac/lambda/TargetType68.out	Fri Nov 13 12:29:23 2015 +0000
+++ b/langtools/test/tools/javac/lambda/TargetType68.out	Fri Nov 13 18:09:36 2015 +0530
@@ -1,3 +1,2 @@
 TargetType68.java:61:32: compiler.err.cant.inherit.from.final: TargetType68.XYChart.Series
-TargetType68.java:61:39: compiler.err.cant.inherit.from.final: TargetType68.XYChart.Series
-2 errors
+1 error