Skip to content

Commit c41ee92

Browse files
cpovirkError Prone Team
authored and
Error Prone Team
committed
In hasAnnotation, don't trigger completion for NullMarked.
Completion can fail under `--release 8`, leading to `warning: unknown enum constant ElementType.MODULE`. This CL is one of a variety of ways that I'll be addressing google/truth#1320. It alone should be sufficient (unless there are other problems that I'm unaware of), but I'll do more for people who might not upgrade Error Prone immediately, and I'll do something cleaner for the `NullArgumentForNonNullParameter` check that makes the known-problematic call to `hasAnnotation`. PiperOrigin-RevId: 651801869
1 parent 8c1a828 commit c41ee92

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static com.google.common.collect.ImmutableSet.toImmutableSet;
2424
import static com.google.common.collect.Iterables.getOnlyElement;
2525
import static com.google.common.collect.Streams.stream;
26+
import static com.google.errorprone.VisitorState.memoize;
2627
import static com.google.errorprone.matchers.JUnitMatchers.JUNIT4_RUN_WITH_ANNOTATION;
2728
import static com.google.errorprone.matchers.Matchers.isSubtypeOf;
2829
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
@@ -913,6 +914,14 @@ private static boolean isInherited(VisitorState state, Name annotationName) {
913914
.get(
914915
annotationName,
915916
name -> {
917+
if (name.equals(NULL_MARKED_NAME.get(state))) {
918+
/*
919+
* We avoid searching for @Inherited on NullMarked not just because we already know
920+
* the answer but also because the search would cause issues under --release 8 on
921+
* account of NullMarked's use of @Target(MODULE, ...).
922+
*/
923+
return false;
924+
}
916925
Symbol annotationSym = state.getSymbolFromName(annotationName);
917926
if (annotationSym == null) {
918927
return false;
@@ -2830,5 +2839,8 @@ public static Stream<? extends ExpressionTree> getCaseExpressions(CaseTree caseT
28302839
}
28312840
}
28322841

2842+
private static final Supplier<Name> NULL_MARKED_NAME =
2843+
memoize(state -> state.getName("org.jspecify.annotations.NullMarked"));
2844+
28332845
private ASTHelpers() {}
28342846
}

0 commit comments

Comments
 (0)