# HG changeset patch # User jjg # Date 1300214935 25200 # Node ID 0f9e5b7f0d7ea0f32626c055f092fd719423d544 # Parent edf03ca749916ff53370dc96b66b3b975930ccee 6988079: Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly Reviewed-by: darcy diff -r edf03ca74991 -r 0f9e5b7f0d7e src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Mar 15 11:41:21 2011 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Mar 15 11:48:55 2011 -0700 @@ -820,13 +820,17 @@ /** The set of package-info files to be processed this round. */ List packageInfoFiles; + /** The number of Messager errors generated in this round. */ + int nMessagerErrors; + /** Create a round (common code). */ - private Round(Context context, int number, int priorWarnings) { + private Round(Context context, int number, int priorErrors, int priorWarnings) { this.context = context; this.number = number; compiler = JavaCompiler.instance(context); log = Log.instance(context); + log.nerrors = priorErrors; log.nwarnings += priorWarnings; log.deferDiagnostics = true; @@ -840,7 +844,7 @@ /** Create the first round. */ Round(Context context, List roots, List classSymbols) { - this(context, 1, 0); + this(context, 1, 0, 0); this.roots = roots; genClassFiles = new HashMap(); @@ -860,7 +864,10 @@ /** Create a new round. */ private Round(Round prev, Set newSourceFiles, Map newClassFiles) { - this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings); + this(prev.nextContext(), + prev.number+1, + prev.nMessagerErrors, + prev.compiler.log.nwarnings); this.genClassFiles = prev.genClassFiles; List parsedFiles = compiler.parseFiles(newSourceFiles); @@ -1014,6 +1021,8 @@ if (taskListener != null) taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); } + + nMessagerErrors = messager.errorCount(); } void showDiagnostics(boolean showAll) { diff -r edf03ca74991 -r 0f9e5b7f0d7e test/tools/javac/processing/6994946/SemanticErrorTest.2.out --- a/test/tools/javac/processing/6994946/SemanticErrorTest.2.out Tue Mar 15 11:41:21 2011 -0700 +++ b/test/tools/javac/processing/6994946/SemanticErrorTest.2.out Tue Mar 15 11:48:55 2011 -0700 @@ -1,4 +1,4 @@ SemanticErrorTest.java:11:46: compiler.err.repeated.interface - compiler.err.proc.messager: Deliberate Error SemanticErrorTest.java:11:46: compiler.err.repeated.interface -1 error +2 errors diff -r edf03ca74991 -r 0f9e5b7f0d7e test/tools/javac/processing/errors/TestErrorCount.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/errors/TestErrorCount.java Tue Mar 15 11:48:55 2011 -0700 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. 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. + */ + +/* + * @test + * @bug 6988079 + * @summary Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly + * @library ../../lib + * @build JavacTestingAbstractProcessor TestErrorCount + * @compile/fail/ref=TestErrorCount.out -XDrawDiagnostics -processor TestErrorCount TestErrorCount.java + */ + +import java.io.*; +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.tools.*; + +public class TestErrorCount extends JavacTestingAbstractProcessor { + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + messager.printMessage(Diagnostic.Kind.ERROR, "intentional error"); + return true; + } +} + diff -r edf03ca74991 -r 0f9e5b7f0d7e test/tools/javac/processing/errors/TestErrorCount.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/errors/TestErrorCount.out Tue Mar 15 11:48:55 2011 -0700 @@ -0,0 +1,3 @@ +- compiler.err.proc.messager: intentional error +- compiler.err.proc.messager: intentional error +2 errors