JDK-8073844 : fatal annotation processing errors do not stop compilation
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2015-02-18
  • Updated: 2016-10-07
  • Resolved: 2016-10-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b139Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.9.0-ea"
Java(TM) SE Runtime Environment (build 1.9.0-ea-b49)
Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b49, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
If the final round of annotation processing is finished and annotation processing has not completed successfully, additional errors should not be emitted. Recent versions of javac9 continue to emit additional diagnostics.

This behaviour was introduced by the fix for https://bugs.openjdk.java.net/browse/JDK-8038455

REGRESSION.  Last worked in version 8u31

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac MyProcessor.java && javac -processor MyProcessor Main.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation should stop after annotation processing fails, as it does with JDK8:

Main.java:2: error: MyProcessor failed
public class Main {
       ^
1 error

ACTUAL -
Instead, an additional diagnostic is emitted after annotation processing has already failed:

Main.java:5: error: cannot find symbol
    new MyProcessor_Generated();
        ^
  symbol:   class MyProcessor_Generated
  location: class Main


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Main.java:2: error: MyProcessor failed
public class Main {
       ^
Main.java:5: error: cannot find symbol
    new MyProcessor_Generated();
        ^
  symbol:   class MyProcessor_Generated
  location: class Main
2 errors


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
=== MyProcessor.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 MyProcessor extends AbstractProcessor {
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.getRootElements().isEmpty()) {
      processingEnv.getMessager().printMessage(Kind.ERROR, "MyProcessor failed",
          roundEnv.getRootElements().iterator().next());
    }

    return false;
  }
  
  @Override
  public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
  }
}
===

=== Main.java ===
public class Main {
  public void m() {
    // A class that we expect our annotation process to generate.
    new MyProcessor_Generated();
  }
}
===
---------- END SOURCE ----------


Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/17a82cb0e4b4 User: lana Date: 2016-10-05 20:01:43 +0000
05-10-2016

URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/17a82cb0e4b4 User: jlahoda Date: 2016-10-04 16:04:45 +0000
04-10-2016

Tested with JDK 8u31, 8u40 b23 and JDK 9 b50 and could confirm this issue. When compiled with JDK 8 (8u31, 8u40, and 8u60), the compilation stopped after the failure of annotation processing as expected. --------------------------------------------------------------------------------------------------------------------------------------------------------------------- >javac MyProcessor.java && javac -processor MyProcessor Main.java Main.java:1: error: MyProcessor failed public class Main { ^ 1 error --------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------- Whereas with JDK 9 ea b50, and additional diagnostic is received even after the failure of annotation processing. >javac" MyProcessor.java && javac -processor MyProcessor Main.java Main.java:1: error: MyProcessor failed public class Main { ^ Main.java:4: error: cannot find symbol new MyProcessor_Generated(); ^ symbol: class MyProcessor_Generated location: class Main 2 errors
25-02-2015