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.
---
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.
- relates to
-
JDK-8328045 javac prints out all recoverable errors when one unrecoverable issue is present
- Closed