# HG changeset patch # User jlahoda # Date 1475595629 -7200 # Node ID 72fcbd6294cb488e7e0f040e5fa2d7b502c2cca0 # Parent 08f8dbf7741e56094c8673014041f766e981c26a 8073844: fatal annotation processing errors do not stop compilation Summary: JavacProcessingEnvironment lets the should-stop policy decide when the compilation should stop. Reviewed-by: jjg diff -r 08f8dbf7741e -r 72fcbd6294cb langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Oct 04 16:25:19 2016 +0200 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Oct 04 17:40:29 2016 +0200 @@ -1336,8 +1336,7 @@ errorStatus = errorStatus || (compiler.errorCount() > 0); - if (!errorStatus) - round.finalCompiler(); + round.finalCompiler(); if (newSourceFiles.size() > 0) roots = roots.appendList(compiler.parseFiles(newSourceFiles)); @@ -1350,10 +1349,8 @@ if (!taskListener.isEmpty()) taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); - if (errorStatus) { - if (compiler.errorCount() == 0) - compiler.log.nerrors++; - return true; + if (errorStatus && compiler.errorCount() == 0) { + compiler.log.nerrors++; } compiler.enterTreesIfNeeded(roots); diff -r 08f8dbf7741e -r 72fcbd6294cb langtools/test/tools/javac/processing/StopAfterError/StopAfterError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/StopAfterError/StopAfterError.java Tue Oct 04 17:40:29 2016 +0200 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, 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 8073844 + * @summary If an error is produced by an annotation processor, the code should not be Attred, \ + * unless requested + * @modules jdk.compiler + * @compile StopAfterError.java + * @compile/fail/ref=StopAfterError.out -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java + * @compile/fail/ref=StopAfterError.out -XDshould-stop.ifError=PROCESS -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java + * @compile/fail/ref=StopAfterErrorContinue.out -XDshould-stop.ifError=ATTR -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java + */ + +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; + +@SupportedAnnotationTypes("*") +public class StopAfterError extends AbstractProcessor { + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Stop!"); + } + return false; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + +} diff -r 08f8dbf7741e -r 72fcbd6294cb langtools/test/tools/javac/processing/StopAfterError/StopAfterError.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/StopAfterError/StopAfterError.out Tue Oct 04 17:40:29 2016 +0200 @@ -0,0 +1,2 @@ +- compiler.err.proc.messager: Stop! +1 error diff -r 08f8dbf7741e -r 72fcbd6294cb langtools/test/tools/javac/processing/StopAfterError/StopAfterErrorAux.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/StopAfterError/StopAfterErrorAux.java Tue Oct 04 17:40:29 2016 +0200 @@ -0,0 +1,6 @@ +/* /nodynamiccopyright/ */ +class StopAfterErrorAux { + public void test() { + should not; get here; + } +} diff -r 08f8dbf7741e -r 72fcbd6294cb langtools/test/tools/javac/processing/StopAfterError/StopAfterErrorContinue.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/StopAfterError/StopAfterErrorContinue.out Tue Oct 04 17:40:29 2016 +0200 @@ -0,0 +1,4 @@ +- compiler.err.proc.messager: Stop! +StopAfterErrorAux.java:4:9: compiler.err.cant.resolve.location: kindname.class, should, , , (compiler.misc.location: kindname.class, StopAfterErrorAux, null) +StopAfterErrorAux.java:4:21: compiler.err.cant.resolve.location: kindname.class, get, , , (compiler.misc.location: kindname.class, StopAfterErrorAux, null) +3 errors