Skip to content

Commit 008cfb0

Browse files
cpovirkError Prone Team
authored andcommitted
Remove redundant complete() call and CompletionFailure check.
Those operations are already [performed during our call to `getSymbolFromString`](https://github.com/google/error-prone/blob/03d15b56478a40534b2b104e21d070d0eebc0701/check_api/src/main/java/com/google/errorprone/VisitorState.java#L432), which returns `null` in case of failure. (I've found the comment that I'm removing a little confusing, too: I think it might be making the point that we don't want to let the `CompletionFailure` propagate because that would fail Error Prone entirely when in fact the check that called `annotationsAmong` might find one of the _other_ annotations it was looking for among the annotations inherited by the class? (We would already have handled any _directly_ present annotations in `annotationsAmong` as well as in `hasAnnotation`.) If so, we're fine, as we handle `null` gracefully. (Of course, this assumes that silently ignoring an annotation that should have been inherited isn't a bad problem that should really lead to a crash. But there's only so much we can do in the presence of an incomplete classpath.) Or is it actually making the point that we want to try to look for `@Inherited` even if completing some _other_ part of the annotation has failed (if that is even possible) and hence we fall through instead of immediately returning `false`? If so, that doesn't currently work because we would already have bailed after the `null` return from `getSymbolFromString`. Anyway, whatever the comment is getting at, this CL is a no-op, so I'm just trying to avoid putting on blinders as I remove the surrounding code.) PiperOrigin-RevId: 651828339
1 parent 3b9ffc2 commit 008cfb0

1 file changed

Lines changed: 0 additions & 7 deletions

File tree

check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
import com.sun.tools.javac.code.Scope;
110110
import com.sun.tools.javac.code.Symbol;
111111
import com.sun.tools.javac.code.Symbol.ClassSymbol;
112-
import com.sun.tools.javac.code.Symbol.CompletionFailure;
113112
import com.sun.tools.javac.code.Symbol.MethodSymbol;
114113
import com.sun.tools.javac.code.Symbol.PackageSymbol;
115114
import com.sun.tools.javac.code.Symbol.TypeSymbol;
@@ -926,12 +925,6 @@ private static boolean isInherited(VisitorState state, Name annotationName) {
926925
if (annotationSym == null) {
927926
return false;
928927
}
929-
try {
930-
annotationSym.complete();
931-
} catch (CompletionFailure e) {
932-
/* @Inherited won't work if the annotation isn't on the classpath, but we can still
933-
check if it's present directly */
934-
}
935928
Symbol inheritedSym = state.getSymtab().inheritedType.tsym;
936929
return annotationSym.attribute(inheritedSym) != null;
937930
});

0 commit comments

Comments
 (0)