changeset 55606:9a8fe0bc38c3

8220632: Suggest recompiling with a larger value of -Xmaxerrs/-Xmaxwarns if diagnostics were suppressed Reviewed-by: jjg
author cushon
date Tue, 26 Mar 2019 16:09:33 -0700
parents f0fec71d2fff
children 2a29e62446bd
files src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java test/langtools/tools/javac/diags/examples/CountErrorRecompile.java test/langtools/tools/javac/diags/examples/CountWarnRecompile.java test/langtools/tools/javac/warnings/MaxDiagsRecompile.all.out test/langtools/tools/javac/warnings/MaxDiagsRecompile.java test/langtools/tools/javac/warnings/MaxDiagsRecompile.max1.out test/langtools/tools/javac/warnings/MaxWarnsRecompile.all.out test/langtools/tools/javac/warnings/MaxWarnsRecompile.java test/langtools/tools/javac/warnings/MaxWarnsRecompile.max1.out
diffstat 11 files changed, 205 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Mar 28 19:43:59 2019 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Mar 26 16:09:33 2019 -0700
@@ -990,6 +990,8 @@
             if (!log.hasDiagnosticListener()) {
                 printCount("error", errorCount());
                 printCount("warn", warningCount());
+                printSuppressedCount(errorCount(), log.nsuppressederrors, "count.error.recompile");
+                printSuppressedCount(warningCount(), log.nsuppressedwarns, "count.warn.recompile");
             }
             if (!taskListener.isEmpty()) {
                 taskListener.finished(new TaskEvent(TaskEvent.Kind.COMPILATION));
@@ -1845,6 +1847,15 @@
         }
     }
 
+    private void printSuppressedCount(int shown, int suppressed, String diagKey) {
+        if (suppressed > 0) {
+            int total = shown + suppressed;
+            log.printLines(WriterKind.ERROR, diagKey,
+                    String.valueOf(shown), String.valueOf(total));
+            log.flush(Log.WriterKind.ERROR);
+        }
+    }
+
     private static long now() {
         return System.currentTimeMillis();
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Mar 28 19:43:59 2019 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Mar 26 16:09:33 2019 -0700
@@ -1636,6 +1636,14 @@
 compiler.misc.count.error.plural=\
     {0} errors
 
+# 0: number, 1: number
+compiler.misc.count.error.recompile=\
+    only showing the first {0} errors, of {1} total; use -Xmaxerrs if you would like to see more
+
+# 0: number, 1: number
+compiler.misc.count.warn.recompile=\
+    only showing the first {0} warnings, of {1} total; use -Xmaxwarns if you would like to see more
+
 # 0: number
 compiler.misc.count.warn=\
     {0} warning
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java	Thu Mar 28 19:43:59 2019 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java	Tue Mar 26 16:09:33 2019 -0700
@@ -419,6 +419,14 @@
      */
     public int nwarnings = 0;
 
+    /** The number of errors encountered after MaxErrors was reached.
+     */
+    public int nsuppressederrors = 0;
+
+    /** The number of warnings encountered after MaxWarnings was reached.
+     */
+    public int nsuppressedwarns = 0;
+
     /** A set of all errors generated so far. This is used to avoid printing an
      *  error message more than once. For each error, a pair consisting of the
      *  source file name and source code position of the error is added to the set.
@@ -708,16 +716,21 @@
                     if (nwarnings < MaxWarnings) {
                         writeDiagnostic(diagnostic);
                         nwarnings++;
+                    } else {
+                        nsuppressedwarns++;
                     }
                 }
                 break;
 
             case ERROR:
-                if (nerrors < MaxErrors &&
-                    (diagnostic.isFlagSet(DiagnosticFlag.API) ||
-                     shouldReport(diagnostic))) {
-                    writeDiagnostic(diagnostic);
-                    nerrors++;
+                if (diagnostic.isFlagSet(DiagnosticFlag.API) ||
+                     shouldReport(diagnostic)) {
+                    if (nerrors < MaxErrors) {
+                        writeDiagnostic(diagnostic);
+                        nerrors++;
+                    } else {
+                        nsuppressederrors++;
+                    }
                 }
                 break;
             }
@@ -844,6 +857,8 @@
             printRawDiag(errWriter, "error: ", pos, msg);
             prompt();
             nerrors++;
+        } else {
+            nsuppressederrors++;
         }
         errWriter.flush();
     }
@@ -852,8 +867,12 @@
      */
     public void rawWarning(int pos, String msg) {
         PrintWriter warnWriter = writers.get(WriterKind.ERROR);
-        if (nwarnings < MaxWarnings && emitWarnings) {
-            printRawDiag(warnWriter, "warning: ", pos, msg);
+        if (emitWarnings) {
+            if (nwarnings < MaxWarnings) {
+                printRawDiag(warnWriter, "warning: ", pos, msg);
+            } else {
+                nsuppressedwarns++;
+            }
         }
         prompt();
         nwarnings++;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/CountErrorRecompile.java	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2019, Google LLC. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.cant.resolve.location
+// key: compiler.misc.count.error.recompile
+// key: compiler.err.error
+// key: compiler.misc.count.error
+// key: compiler.misc.kindname.class
+// key: compiler.misc.location
+// options: -Xmaxerrs 1
+// run: backdoor
+
+class CountErrorRecompile {
+
+    NoSuchSymbol1 f1;
+    NoSuchSymbol2 f2;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/CountWarnRecompile.java	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2019, Google LLC. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.warn.raw.class.use
+// key: compiler.misc.count.warn
+// key: compiler.misc.kindname.interface
+// key: compiler.misc.where.description.typevar
+// key: compiler.misc.where.typevar
+// key: compiler.warn.lintOption
+// key: compiler.warn.warning
+// key: compiler.misc.count.warn.recompile
+// options: -Xlint:all -Xmaxwarns 1
+// run: backdoor
+
+import java.util.List;
+
+class CountWarnRecompile {
+
+    List x1;
+    List x2;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/warnings/MaxDiagsRecompile.all.out	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,5 @@
+MaxDiagsRecompile.java:28:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol1, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
+MaxDiagsRecompile.java:29:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol2, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
+MaxDiagsRecompile.java:30:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol3, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
+MaxDiagsRecompile.java:31:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol4, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
+4 errors
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/warnings/MaxDiagsRecompile.java	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019, Google LLC. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * @test
+ * @summary suggest recompiling with -Xmaxerrs
+ * @compile/fail/ref=MaxDiagsRecompile.max1.out -XDrawDiagnostics -Xmaxerrs 1 MaxDiagsRecompile.java
+ * @compile/fail/ref=MaxDiagsRecompile.all.out -XDrawDiagnostics -Xmaxerrs 4 MaxDiagsRecompile.java
+ */
+public class MaxDiagsRecompile {
+
+  NoSuchSymbol1 f1;
+  NoSuchSymbol2 f2;
+  NoSuchSymbol3 f3;
+  NoSuchSymbol4 f4;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/warnings/MaxDiagsRecompile.max1.out	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,3 @@
+MaxDiagsRecompile.java:28:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol1, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
+1 error
+only showing the first 1 errors, of 4 total; use -Xmaxerrs if you would like to see more
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/warnings/MaxWarnsRecompile.all.out	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,5 @@
+MaxWarnsRecompile.java:30:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
+MaxWarnsRecompile.java:31:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
+MaxWarnsRecompile.java:32:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
+MaxWarnsRecompile.java:33:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
+4 warnings
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/warnings/MaxWarnsRecompile.java	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019, Google LLC. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+import java.util.List;
+
+/*
+ * @test
+ * @summary suggest recompiling with -Xmaxwarns
+ * @compile/ref=MaxWarnsRecompile.max1.out -XDrawDiagnostics -Xlint:all -Xmaxwarns 1 MaxWarnsRecompile.java
+ * @compile/ref=MaxWarnsRecompile.all.out -XDrawDiagnostics -Xlint:all -Xmaxwarns 4 MaxWarnsRecompile.java
+ */
+public class MaxWarnsRecompile {
+
+  List x1;
+  List x2;
+  List x3;
+  List x4;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/warnings/MaxWarnsRecompile.max1.out	Tue Mar 26 16:09:33 2019 -0700
@@ -0,0 +1,3 @@
+MaxWarnsRecompile.java:30:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
+1 warning
+only showing the first 1 warnings, of 4 total; use -Xmaxwarns if you would like to see more