Tue, 15 Mar 2011 11:48:55 -0700
6988079: Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Mar 15 11:41:21 2011 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Mar 15 11:48:55 2011 -0700 1.3 @@ -820,13 +820,17 @@ 1.4 /** The set of package-info files to be processed this round. */ 1.5 List<PackageSymbol> packageInfoFiles; 1.6 1.7 + /** The number of Messager errors generated in this round. */ 1.8 + int nMessagerErrors; 1.9 + 1.10 /** Create a round (common code). */ 1.11 - private Round(Context context, int number, int priorWarnings) { 1.12 + private Round(Context context, int number, int priorErrors, int priorWarnings) { 1.13 this.context = context; 1.14 this.number = number; 1.15 1.16 compiler = JavaCompiler.instance(context); 1.17 log = Log.instance(context); 1.18 + log.nerrors = priorErrors; 1.19 log.nwarnings += priorWarnings; 1.20 log.deferDiagnostics = true; 1.21 1.22 @@ -840,7 +844,7 @@ 1.23 1.24 /** Create the first round. */ 1.25 Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols) { 1.26 - this(context, 1, 0); 1.27 + this(context, 1, 0, 0); 1.28 this.roots = roots; 1.29 genClassFiles = new HashMap<String,JavaFileObject>(); 1.30 1.31 @@ -860,7 +864,10 @@ 1.32 /** Create a new round. */ 1.33 private Round(Round prev, 1.34 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) { 1.35 - this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings); 1.36 + this(prev.nextContext(), 1.37 + prev.number+1, 1.38 + prev.nMessagerErrors, 1.39 + prev.compiler.log.nwarnings); 1.40 this.genClassFiles = prev.genClassFiles; 1.41 1.42 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles); 1.43 @@ -1014,6 +1021,8 @@ 1.44 if (taskListener != null) 1.45 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); 1.46 } 1.47 + 1.48 + nMessagerErrors = messager.errorCount(); 1.49 } 1.50 1.51 void showDiagnostics(boolean showAll) {
2.1 --- a/test/tools/javac/processing/6994946/SemanticErrorTest.2.out Tue Mar 15 11:41:21 2011 -0700 2.2 +++ b/test/tools/javac/processing/6994946/SemanticErrorTest.2.out Tue Mar 15 11:48:55 2011 -0700 2.3 @@ -1,4 +1,4 @@ 2.4 SemanticErrorTest.java:11:46: compiler.err.repeated.interface 2.5 - compiler.err.proc.messager: Deliberate Error 2.6 SemanticErrorTest.java:11:46: compiler.err.repeated.interface 2.7 -1 error 2.8 +2 errors
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/processing/errors/TestErrorCount.java Tue Mar 15 11:48:55 2011 -0700 3.3 @@ -0,0 +1,46 @@ 3.4 +/* 3.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 6988079 3.30 + * @summary Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly 3.31 + * @library ../../lib 3.32 + * @build JavacTestingAbstractProcessor TestErrorCount 3.33 + * @compile/fail/ref=TestErrorCount.out -XDrawDiagnostics -processor TestErrorCount TestErrorCount.java 3.34 + */ 3.35 + 3.36 +import java.io.*; 3.37 +import java.util.*; 3.38 +import javax.annotation.processing.*; 3.39 +import javax.lang.model.element.*; 3.40 +import javax.tools.*; 3.41 + 3.42 +public class TestErrorCount extends JavacTestingAbstractProcessor { 3.43 + @Override 3.44 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 3.45 + messager.printMessage(Diagnostic.Kind.ERROR, "intentional error"); 3.46 + return true; 3.47 + } 3.48 +} 3.49 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/processing/errors/TestErrorCount.out Tue Mar 15 11:48:55 2011 -0700 4.3 @@ -0,0 +1,3 @@ 4.4 +- compiler.err.proc.messager: intentional error 4.5 +- compiler.err.proc.messager: intentional error 4.6 +2 errors