Issue with symbol completion failures during the final round of annotation processing

Liam Miller-Cushon cushon at google.com
Mon Oct 20 20:23:37 UTC 2014


I encountered an issue that causes symbol completion failures to be ignored
during the final round of annotation processing. A diagnostic is printed to
stderr, but the compilation still finishes with a 0 exit code.

Is this a known issue? It affects javac 6, 7, and 8. It does not affect
javac 9, probably thanks to JDK-8038455.

Here's the repro:

$ javac -cp $JAVA_HOME/lib/tools.jar CompletionFailureProcessor.java
$ javac -cp $JAVA_HOME/lib/tools.jar:. -processor
CompletionFailureProcessor Test.java
error: cannot access Test
  Consult the following stack trace for details.
  com.sun.tools.javac.code.Symbol$CompletionFailure:
  ...
$ echo $?
0

=== Test.java ===
class Test {}
===

=== CompletionFailureProcessor.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.Element;
import javax.lang.model.element.TypeElement;

import com.sun.tools.javac.code.Symbol;

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

  public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
  }

  Element element;

  @Override
  public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {

    if (roundEnv.getRootElements().isEmpty()) {
      // last round has no root elements
      throw new Symbol.CompletionFailure((Symbol) element, "");
    } else {
      // save an element for constructing the CompletionFailure next round
      element = roundEnv.getRootElements().iterator().next();
    }

    return false;
  }
}
===
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20141020/7e1a9945/attachment.html>


More information about the compiler-dev mailing list