Recoverable errors may be reported before unrecoverable errors when annotation processing is skipped

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 23
    • Affects Version/s: 8, 11, 17, 21, 22, 23
    • Component/s: tools
    • None
    • b07

      Consider this annotation processor:
      ---
      import java.io.IOException;
      import java.io.Writer;
      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;

      @SupportedAnnotationTypes("*")
      public class Processor extends AbstractProcessor {

          private int round;

          @Override
          public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
              if (round++ == 0) {
                  try (Writer w = processingEnv.getFiler().createSourceFile("Test").openWriter()) {
                      w.append("public class Test {}");
                  } catch (IOException ex) {
                      ex.printStackTrace();
                  }
              }
              return false;
          }

          @Override
          public SourceVersion getSupportedSourceVersion() {
              return SourceVersion.latestSupported();
          }

      }
      ---

      This source code:
      ---
      public class X {
          @SuppressWarnings("")
          @SuppressWarnings("")
          private Test test() {
              return null;
          }
      }
      ---

      When compiling X.java with the processor, the reported errors are:
      ---
      $ javac -processorpath . -processor Processor X.java
      X.java:4: error: cannot find symbol
          private Test test() {
                  ^
        symbol: class Test
        location: class X
      X.java:3: error: SuppressWarnings is not a repeatable annotation interface
          @SuppressWarnings("")
          ^
      2 errors
      ---

      which is highly confusing, as the first error would be resolved by the AP, which is not run due to the second, unrecoverable, error.

            Assignee:
            Jan Lahoda
            Reporter:
            Jan Lahoda
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: