Skip to content

Commit

Permalink
Merge pull request #6422 from dbalek/dbalek/apt-fix
Browse files Browse the repository at this point in the history
Handle errors in annotation processor initialization
  • Loading branch information
dbalek authored Sep 8, 2023
2 parents 1e49409 + c916ce6 commit 1867e0d
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -953,22 +953,44 @@ public ErrorToleratingProcessor(Processor delegate) {

@Override
public Set<String> getSupportedOptions() {
if (!valid) {
return Collections.emptySet();
}
return delegate.getSupportedOptions();
}

@Override
public Set<String> getSupportedAnnotationTypes() {
if (!valid) {
return Collections.emptySet();
}
return delegate.getSupportedAnnotationTypes();
}

@Override
public SourceVersion getSupportedSourceVersion() {
if (!valid) {
return SourceVersion.latest();
}
return delegate.getSupportedSourceVersion();
}

@Override
public void init(ProcessingEnvironment processingEnv) {
delegate.init(processingEnv);
try {
delegate.init(processingEnv);
} catch (ClientCodeException | ThreadDeath | Abort err) {
valid = false;
throw err;
} catch (Throwable t) {
valid = false;
StringBuilder exception = new StringBuilder();
exception.append(t.getMessage()).append("\n");
for (StackTraceElement ste : t.getStackTrace()) {
exception.append(ste).append("\n");
}
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, Bundle.ERR_ProcessorException(delegate.getClass().getName(), exception.toString()));
}
this.processingEnv = processingEnv;
}

Expand Down Expand Up @@ -998,6 +1020,9 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment

@Override
public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
if (!valid) {
return Collections.emptySet();
}
return delegate.getCompletions(element, annotation, member, userText);
}

Expand Down

0 comments on commit 1867e0d

Please sign in to comment.