there is no additional method with name matching {@code expectedNoArgMethod}
*
*/
- @Nullable
- private static MethodTree checkMethodPresence(ClassTree classTree, VisitorState state) {
+ private static @Nullable MethodTree checkMethodPresence(ClassTree classTree, VisitorState state) {
TypeSymbol symbol = ASTHelpers.getSymbol(classTree);
if (symbol.getKind() != ElementKind.CLASS) {
return null;
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/EqualsNaN.java b/core/src/main/java/com/google/errorprone/bugpatterns/EqualsNaN.java
index 7de93caed52..1219537154f 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/EqualsNaN.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/EqualsNaN.java
@@ -29,7 +29,7 @@
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCExpression;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author lowasser@google.com (Louis Wasserman)
@@ -77,8 +77,7 @@ private static CharSequence toString(JCTree tree, VisitorState state) {
return (source == null) ? tree.toString() : source;
}
- @Nullable
- private static String matchNaN(ExpressionTree tree) {
+ private static @Nullable String matchNaN(ExpressionTree tree) {
Symbol sym = ASTHelpers.getSymbol(tree);
if (sym != null
&& sym.owner != null
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ExpectedExceptionChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/ExpectedExceptionChecker.java
index dd80d504c18..7ba994e3741 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/ExpectedExceptionChecker.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/ExpectedExceptionChecker.java
@@ -65,7 +65,7 @@
import java.util.Deque;
import java.util.List;
import java.util.regex.Pattern;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(summary = "Prefer assertThrows to ExpectedException", severity = WARNING)
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ForEachIterable.java b/core/src/main/java/com/google/errorprone/bugpatterns/ForEachIterable.java
index b655a745e9b..63d864b2b9c 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/ForEachIterable.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/ForEachIterable.java
@@ -50,7 +50,7 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTag;
import java.util.List;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(summary = "This loop can be replaced with an enhanced for loop.", severity = SUGGESTION)
@@ -196,8 +196,7 @@ public Void visitIdentifier(IdentifierTree identifierTree, Void unused) {
return uses.build();
}
- @Nullable
- private static VariableTree existingVariable(
+ private static @Nullable VariableTree existingVariable(
VarSymbol varSymbol, StatementTree body, VisitorState state) {
if (!(body instanceof BlockTree)) {
return null;
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ForOverrideChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/ForOverrideChecker.java
index e25438fcfaf..f20ae10e09f 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/ForOverrideChecker.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/ForOverrideChecker.java
@@ -44,8 +44,8 @@
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.code.Type;
import java.util.stream.Stream;
-import javax.annotation.Nullable;
import javax.lang.model.element.Modifier;
+import org.jspecify.annotations.Nullable;
/**
* Verifies that methods marked {@link com.google.errorprone.annotations.ForOverride} are only
@@ -147,8 +147,7 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
* By 'direct', we mean that if the leaf is part of a field initializer of a class, then it is
* considered to not be part of any method.
*/
- @Nullable
- private static MethodTree findDirectMethod(TreePath path) {
+ private static @Nullable MethodTree findDirectMethod(TreePath path) {
while (true) {
path = path.getParentPath();
if (path != null) {
@@ -205,8 +204,7 @@ private static ImmutableList getOverriddenMethods(
}
/** Get the outermost class/interface/enum of an element, or null if none. */
- @Nullable
- private static Type getOutermostClass(VisitorState state) {
+ private static @Nullable Type getOutermostClass(VisitorState state) {
return findLast(
stream(state.getPath())
.filter(t -> t instanceof ClassTree)
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChaining.java b/core/src/main/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChaining.java
index ec8f5c1a2ca..c722309ca47 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChaining.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChaining.java
@@ -55,7 +55,7 @@
import java.util.Deque;
import java.util.List;
import java.util.regex.Pattern;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Migrates Truth subjects from a manual "test and fail" approach to one using {@code
@@ -115,8 +115,7 @@ public Description matchIf(IfTree ifTree, VisitorState state) {
state.getSourceForNode(actualAndExpected.get(1)))));
}
- @Nullable
- private static ImmutableList findActualAndExpected(
+ private static @Nullable ImmutableList findActualAndExpected(
ExpressionTree condition, VisitorState state) {
/*
* Note that all these look "backward": If the code is "if (foo == bar) { fail }," then the
@@ -135,8 +134,7 @@ private static ImmutableList findActualAndExpected(
}
}
- @Nullable
- private static ImmutableList findActualAndExpectedForPossibleEqualsCall(
+ private static @Nullable ImmutableList findActualAndExpectedForPossibleEqualsCall(
ExpressionTree possiblyEqualsCall, VisitorState state) {
if (!EQUALS_LIKE_METHOD.matches(possiblyEqualsCall, state)) {
return null;
@@ -151,8 +149,7 @@ private static ImmutableList findActualAndExpectedForPossibleEqu
getOnlyElement(args));
}
- @Nullable
- private static ImmutableList findActualAndExpectedForBinaryOp(
+ private static @Nullable ImmutableList findActualAndExpectedForBinaryOp(
BinaryTree binaryTree, VisitorState state) {
/*
* It's actually enough for *either* to be a primitive, thanks to autounboxing (and enough for
@@ -214,8 +211,7 @@ private static boolean isCallToFail(StatementTree then, VisitorState state) {
* that case, they appear "backward" as we walk the tree (i.e., bar, foo), so we add each one to
* the beginning of the list as we go.
*/
- @Nullable
- static String makeCheckDescription(ExpressionTree actual, VisitorState state) {
+ static @Nullable String makeCheckDescription(ExpressionTree actual, VisitorState state) {
/*
* This conveniently also acts as a check that the actual and expected values aren't backward,
* since the actual value is almost always an invocation on actual() and the expected value is
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java b/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java
index 8307cc6c725..55b938d35d1 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java
@@ -68,8 +68,8 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import javax.annotation.Nullable;
import javax.inject.Inject;
+import org.jspecify.annotations.Nullable;
/** Matches comparison of proto fields to {@code null}. */
@BugPattern(
@@ -193,9 +193,9 @@ public Void visitVariable(VariableTree variable, Void unused) {
private Optional getInitializer(ExpressionTree tree) {
return Optional.ofNullable(
new SimpleTreeVisitor() {
- @Nullable
@Override
- public ExpressionTree visitMethodInvocation(MethodInvocationTree node, Void unused) {
+ public @Nullable ExpressionTree visitMethodInvocation(
+ MethodInvocationTree node, Void unused) {
return PROTO_RECEIVER.matches(node, state) ? node : null;
}
@@ -270,8 +270,7 @@ private Optional getFixer(ExpressionTree tree, VisitorState state) {
.findFirst();
}
- @Nullable
- private ExpressionTree getEffectiveTree(ExpressionTree tree) {
+ private @Nullable ExpressionTree getEffectiveTree(ExpressionTree tree) {
return tree.getKind() == Kind.IDENTIFIER
? effectivelyFinalValues.getOrDefault(ASTHelpers.getSymbol(tree), tree)
: tree;
@@ -322,9 +321,8 @@ private interface Fixer {
private enum GetterTypes {
OPTIONAL_GET {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!OPTIONAL_GET_MATCHER.matches(tree, state)) {
return null;
}
@@ -334,9 +332,8 @@ Fixer match(ExpressionTree tree, VisitorState state) {
}
},
GUAVA_OPTIONAL_GET {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!GUAVA_OPTIONAL_GET_MATCHER.matches(tree, state)) {
return null;
}
@@ -345,9 +342,8 @@ Fixer match(ExpressionTree tree, VisitorState state) {
}
},
MULTIMAP_GET {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!MULTIMAP_GET_MATCHER.matches(tree, state)) {
return null;
}
@@ -362,9 +358,8 @@ Fixer match(ExpressionTree tree, VisitorState state) {
}
},
TABLE_ROW_GET {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!TABLE_ROW_MATCHER.matches(tree, state)) {
return null;
}
@@ -379,9 +374,8 @@ Fixer match(ExpressionTree tree, VisitorState state) {
}
},
TABLE_COLUMN_GET {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!TABLE_COLUMN_MATCHER.matches(tree, state)) {
return null;
}
@@ -396,17 +390,15 @@ Fixer match(ExpressionTree tree, VisitorState state) {
}
},
PRIMITIVE {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
var type = getType(tree);
return type != null && type.isPrimitive() ? GetterTypes::emptyFix : null;
}
},
VALUE_OF {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!NON_NULL_VALUE_OF.matches(tree, state)) {
return null;
}
@@ -416,9 +408,8 @@ Fixer match(ExpressionTree tree, VisitorState state) {
},
/** {@code proto.getFoo()} */
SCALAR {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!PROTO_RECEIVER.matches(tree, state)) {
return null;
}
@@ -465,9 +456,8 @@ private String replaceLast(String text, String pattern, String replacement) {
},
/** {@code proto.getRepeatedFoo(index)} */
VECTOR_INDEXED {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!PROTO_RECEIVER.matches(tree, state)) {
return null;
}
@@ -499,9 +489,8 @@ private String generateFix(
},
/** {@code proto.getRepeatedFooList()} */
VECTOR {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!PROTO_RECEIVER.matches(tree, state)) {
return null;
}
@@ -529,9 +518,8 @@ private String generateFix(
},
/** {@code proto.getField(f)} or {@code proto.getExtension(outer, extension)}; */
EXTENSION_METHOD {
- @Nullable
@Override
- Fixer match(ExpressionTree tree, VisitorState state) {
+ @Nullable Fixer match(ExpressionTree tree, VisitorState state) {
if (!PROTO_RECEIVER.matches(tree, state)) {
return null;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongType.java b/core/src/main/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongType.java
index 42f503085f2..1bec8f914b2 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongType.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongType.java
@@ -43,7 +43,7 @@
import com.sun.source.util.TreePath;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.code.Types;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author sulku@google.com (Marsela Sulku)
@@ -147,8 +147,7 @@ static class TreeScannerInstanceOfWrongType extends TreeScannerlong literal with a lower-case ell for a suffix (e.g. 234l
@@ -64,8 +64,7 @@ public boolean matches(LiteralTree literalTree, VisitorState state) {
* Extracts the long literal corresponding to a given {@link LiteralTree} node from the source
* code as a string. Returns null if the source code is not available.
*/
- @Nullable
- private static String getLongLiteral(LiteralTree literalTree, VisitorState state) {
+ private static @Nullable String getLongLiteral(LiteralTree literalTree, VisitorState state) {
JCLiteral longLiteral = (JCLiteral) literalTree;
CharSequence sourceFile = state.getSourceCode();
if (sourceFile == null) {
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java b/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java
index fbbe69dca54..a6d102843c0 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java
@@ -40,8 +40,8 @@
import com.sun.tools.javac.code.Symbol;
import java.util.HashSet;
import java.util.Set;
-import javax.annotation.Nullable;
import javax.lang.model.element.ElementKind;
+import org.jspecify.annotations.Nullable;
/**
* Matches test helpers which require a terminating method to be called.
@@ -123,8 +123,7 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
.orElse(NO_MATCH);
}
- @Nullable
- private static ExpressionTree getUltimateReceiver(ExpressionTree tree) {
+ private static @Nullable ExpressionTree getUltimateReceiver(ExpressionTree tree) {
return findLast(streamReceivers(tree)).orElse(null);
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStream.java b/core/src/main/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStream.java
index 02fd93a71a4..76ae165d5ca 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStream.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStream.java
@@ -34,7 +34,7 @@
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Identify the backing collection source of a stream and reports if the source is mutated during
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/NarrowingCompoundAssignment.java b/core/src/main/java/com/google/errorprone/bugpatterns/NarrowingCompoundAssignment.java
index b1fdfc12bc6..9876cffdfcf 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/NarrowingCompoundAssignment.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/NarrowingCompoundAssignment.java
@@ -37,7 +37,7 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.tree.JCTree.JCBinary;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
@@ -121,8 +121,7 @@ public Description matchCompoundAssignment(CompoundAssignmentTree tree, VisitorS
}
/** Classifies bad casts. */
- @Nullable
- private static String identifyBadCast(Type lhs, Type rhs, Types types) {
+ private static @Nullable String identifyBadCast(Type lhs, Type rhs, Types types) {
if (!lhs.isPrimitive()) {
return null;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/NonCanonicalType.java b/core/src/main/java/com/google/errorprone/bugpatterns/NonCanonicalType.java
index d679e69b4ba..1de0b2134f8 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/NonCanonicalType.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/NonCanonicalType.java
@@ -37,7 +37,7 @@
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Flags types being referred to by their non-canonical name. */
@BugPattern(
@@ -80,8 +80,7 @@ public Description matchMemberSelect(MemberSelectTree tree, VisitorState state)
.build();
}
- @Nullable
- private static String canonicalName(MemberSelectTree tree) {
+ private static @Nullable String canonicalName(MemberSelectTree tree) {
Symbol sym = getSymbol(tree);
if (sym == null) {
return null;
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/NullOptional.java b/core/src/main/java/com/google/errorprone/bugpatterns/NullOptional.java
index d35400bf5e7..91c3f414470 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/NullOptional.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/NullOptional.java
@@ -42,7 +42,7 @@
import com.sun.tools.javac.code.Type.ArrayType;
import java.util.Iterator;
import java.util.List;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Flags passing literal null to {@code Optional}-accepting APIs. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/RedundantOverride.java b/core/src/main/java/com/google/errorprone/bugpatterns/RedundantOverride.java
index 4d085d6294f..89e0d5bb77d 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/RedundantOverride.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/RedundantOverride.java
@@ -46,8 +46,8 @@
import com.sun.tools.javac.code.Symbol.VarSymbol;
import java.util.Objects;
import java.util.Optional;
-import javax.annotation.Nullable;
import javax.lang.model.element.Modifier;
+import org.jspecify.annotations.Nullable;
/** Removes overrides which purely pass through to the method in the super class. */
@BugPattern(
@@ -130,8 +130,7 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
return describeMatch(tree, SuggestedFix.delete(tree));
}
- @Nullable
- private static MethodInvocationTree getSingleInvocation(StatementTree statement) {
+ private static @Nullable MethodInvocationTree getSingleInvocation(StatementTree statement) {
return statement.accept(
new SimpleTreeVisitor() {
@Override
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java b/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java
index 4b08e933309..3f7e4103f27 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java
@@ -61,7 +61,7 @@
import java.util.Map;
import java.util.regex.Pattern;
import javax.inject.Inject;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/** A BugPattern; see the summary. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/RemoveUnusedImports.java b/core/src/main/java/com/google/errorprone/bugpatterns/RemoveUnusedImports.java
index 9bdba892ae2..5665c64a501 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/RemoveUnusedImports.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/RemoveUnusedImports.java
@@ -46,7 +46,7 @@
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.DCTree.DCReference;
import java.util.LinkedHashSet;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author gak@google.com (Gregory Kick)
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/RestrictedApiChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/RestrictedApiChecker.java
index f04fafa0b72..3490497d2dd 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/RestrictedApiChecker.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/RestrictedApiChecker.java
@@ -59,7 +59,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Stream;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Check for non-allowlisted callers to RestrictedApiChecker. */
@BugPattern(
@@ -194,8 +194,8 @@ private Description checkMethodUse(
.orElse(NO_MATCH);
}
- @Nullable
- private static Attribute.Compound getRestrictedApiAnnotation(Symbol sym, VisitorState state) {
+ private static Attribute.@Nullable Compound getRestrictedApiAnnotation(
+ Symbol sym, VisitorState state) {
if (sym == null) {
return null;
}
@@ -203,7 +203,7 @@ private static Attribute.Compound getRestrictedApiAnnotation(Symbol sym, Visitor
}
private Description checkRestriction(
- @Nullable Attribute.Compound attribute, Tree where, VisitorState state) {
+ Attribute.@Nullable Compound attribute, Tree where, VisitorState state) {
if (attribute == null) {
return NO_MATCH;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java b/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java
index 9669aded089..51438b859f8 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java
@@ -52,7 +52,7 @@
import javax.inject.Inject;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Name;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/** Looks for types being shadowed by other types in a way that may be confusing. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SelfAssignment.java b/core/src/main/java/com/google/errorprone/bugpatterns/SelfAssignment.java
index 8d0175874b6..5e35e376800 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/SelfAssignment.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/SelfAssignment.java
@@ -49,7 +49,7 @@
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* TODO(eaftan): Consider cases where the parent is not a statement or there is no parent?
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SelfEquals.java b/core/src/main/java/com/google/errorprone/bugpatterns/SelfEquals.java
index d53df09abca..51b553ac780 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/SelfEquals.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/SelfEquals.java
@@ -46,7 +46,7 @@
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import java.util.List;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author bhagwani@google.com (Sumit Bhagwani)
@@ -93,8 +93,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
return description.build();
}
- @Nullable
- protected static SuggestedFix fieldFix(Tree toReplace, VisitorState state) {
+ protected static @Nullable SuggestedFix fieldFix(Tree toReplace, VisitorState state) {
TreePath path = state.getPath();
while (path != null
&& path.getLeaf().getKind() != Kind.CLASS
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java b/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java
index 90d20ebf61f..45b84a1f79d 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java
@@ -34,7 +34,7 @@
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.Name;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Logic for inspecting static imports used by {@link NonCanonicalStaticImport}, {@link
@@ -91,8 +91,7 @@ private static StaticImportInfo create(
* {@code null} otherwise, e.g. because the import is non-static, or an on-demand import, or
* statically imports a field or method.
*/
- @Nullable
- public static StaticImportInfo tryCreate(ImportTree tree, VisitorState state) {
+ public static @Nullable StaticImportInfo tryCreate(ImportTree tree, VisitorState state) {
if (!tree.isStatic()) {
return null;
}
@@ -109,8 +108,7 @@ public static StaticImportInfo tryCreate(ImportTree tree, VisitorState state) {
return tryCreate(access, state);
}
- @Nullable
- public static StaticImportInfo tryCreate(MemberSelectTree access, VisitorState state) {
+ public static @Nullable StaticImportInfo tryCreate(MemberSelectTree access, VisitorState state) {
Name identifier = (Name) access.getIdentifier();
Symbol importedType = getSymbol(access.getExpression());
if (importedType == null) {
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/StringSplitter.java b/core/src/main/java/com/google/errorprone/bugpatterns/StringSplitter.java
index 5caf54ec10f..3b71336f016 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/StringSplitter.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/StringSplitter.java
@@ -56,7 +56,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(summary = "String.split(String) has surprising behavior", severity = WARNING)
@@ -294,8 +294,7 @@ private static SuggestedFix.Builder replaceWithSplitter(
throw new AssertionError(receiver);
}
- @Nullable
- private static TreePath findEnclosing(VisitorState state) {
+ private static @Nullable TreePath findEnclosing(VisitorState state) {
for (TreePath path = state.getPath(); path != null; path = path.getParentPath()) {
switch (path.getLeaf().getKind()) {
case METHOD:
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SwitchDefault.java b/core/src/main/java/com/google/errorprone/bugpatterns/SwitchDefault.java
index bf114cc9711..4bd82b4c43b 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/SwitchDefault.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/SwitchDefault.java
@@ -34,7 +34,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/TestExceptionChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/TestExceptionChecker.java
index ccb646fcc9f..6f9eb72f103 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/TestExceptionChecker.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/TestExceptionChecker.java
@@ -44,7 +44,7 @@
import com.sun.tools.javac.tree.JCTree.Tag;
import java.util.Collection;
import java.util.List;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
@@ -114,8 +114,7 @@ private static SuggestedFix buildFix(
* Searches the annotation list for {@code @Test(expected=...)}. If found, deletes the exception
* attribute from the annotation, and returns its value.
*/
- @Nullable
- private static JCExpression deleteExpectedException(
+ private static @Nullable JCExpression deleteExpectedException(
SuggestedFix.Builder fix, List annotations, VisitorState state) {
Type testAnnotation = ORG_JUNIT_TEST.get(state);
for (JCAnnotation annotationTree : annotations) {
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/TruthAssertExpected.java b/core/src/main/java/com/google/errorprone/bugpatterns/TruthAssertExpected.java
index a974b30ad47..ad72c3c2d68 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/TruthAssertExpected.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/TruthAssertExpected.java
@@ -44,7 +44,7 @@
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Type;
import java.util.List;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Detects usages of Truth assertions with the expected and actual values reversed.
@@ -132,9 +132,8 @@ public List extends ExpressionTree> visitNewClass(NewClassTree node, Void unus
return node.getArguments();
}
- @Nullable
@Override
- public List extends ExpressionTree> visitMethodInvocation(
+ public @Nullable List extends ExpressionTree> visitMethodInvocation(
MethodInvocationTree node, Void unused) {
MethodSymbol symbol = ASTHelpers.getSymbol(node);
if (!symbol.isStatic()) {
@@ -189,8 +188,7 @@ private static Matcher hasReceiverMatching(Matcher matcher) {
return streamReceivers(tree).filter(t -> matcher.matches(t, state)).findFirst().orElse(null);
}
@@ -199,8 +197,7 @@ private static ExpressionTree findReceiverMatching(
* Walks up the provided {@link ExpressionTree} to find the {@link IdentifierTree identifier} that
* it stems from. Returns {@code null} if the tree doesn't terminate in an identifier.
*/
- @Nullable
- private static IdentifierTree getRootIdentifier(ExpressionTree tree) {
+ private static @Nullable IdentifierTree getRootIdentifier(ExpressionTree tree) {
if (tree == null) {
return null;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java b/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java
index bf827bd6e0d..cf522f39634 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java
@@ -43,9 +43,9 @@
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
-import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.lang.model.type.TypeKind;
+import org.jspecify.annotations.Nullable;
/**
* Methods to answer the question: are these two types "compatible" with each other, in the context
@@ -364,14 +364,11 @@ public abstract static class TypeCompatibilityReport {
public abstract boolean isCompatible();
- @Nullable
- public abstract Type lhs();
+ public abstract @Nullable Type lhs();
- @Nullable
- public abstract Type rhs();
+ public abstract @Nullable Type rhs();
- @Nullable
- public abstract String extraReason();
+ public abstract @Nullable String extraReason();
static TypeCompatibilityReport compatible() {
return COMPATIBLE;
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryAnonymousClass.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryAnonymousClass.java
index 4ec4f665604..3b7f0a25bd5 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryAnonymousClass.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryAnonymousClass.java
@@ -55,9 +55,9 @@
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import java.util.Objects;
import java.util.Optional;
-import javax.annotation.Nullable;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
@@ -233,8 +233,8 @@ public Void visitIdentifier(IdentifierTree node, Void unused) {
/**
* Replace the given {@code node} with the method reference specified by {@code this.newName}.
*/
- @Nullable
- private SuggestedFix replaceUseWithMethodReference(ExpressionTree node, VisitorState state) {
+ private @Nullable SuggestedFix replaceUseWithMethodReference(
+ ExpressionTree node, VisitorState state) {
Tree parent = state.getPath().getParentPath().getLeaf();
if (parent instanceof MemberSelectTree
&& ((MemberSelectTree) parent).getExpression().equals(node)) {
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryLambda.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryLambda.java
index 46a81029ff0..dba027bd357 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryLambda.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryLambda.java
@@ -68,7 +68,7 @@
import java.util.function.Predicate;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java
index 0e8f41a500e..d01f7386a85 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java
@@ -116,13 +116,13 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.Name;
import javax.lang.model.type.NullType;
import javax.tools.JavaFileObject;
+import org.jspecify.annotations.Nullable;
/** Bugpattern to detect unused declarations. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UseEnumSwitch.java b/core/src/main/java/com/google/errorprone/bugpatterns/UseEnumSwitch.java
index c52ecdb244c..29417dba95d 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/UseEnumSwitch.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/UseEnumSwitch.java
@@ -24,7 +24,7 @@
import com.sun.source.tree.ExpressionTree;
import com.sun.tools.javac.code.Symbol;
import javax.lang.model.element.ElementKind;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/android/FragmentInjection.java b/core/src/main/java/com/google/errorprone/bugpatterns/android/FragmentInjection.java
index bb8a0fabea3..e4232014be6 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/android/FragmentInjection.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/android/FragmentInjection.java
@@ -51,8 +51,8 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.util.FatalError;
import com.sun.tools.javac.util.Name;
-import javax.annotation.Nullable;
import javax.lang.model.element.Modifier;
+import org.jspecify.annotations.Nullable;
/**
* @author epmjohnston@google.com (Emily P.M. Johnston)
@@ -121,8 +121,7 @@ public Description matchClass(ClassTree tree, VisitorState state) {
* Return the first method tree on the given class tree that matches the given method matcher,
* or null if one does not exist.
*/
- @Nullable
- private static MethodTree getMethod(
+ private static @Nullable MethodTree getMethod(
Matcher methodMatcher, ClassTree classTree, VisitorState state) {
for (Tree member : classTree.getMembers()) {
if (member instanceof MethodTree) {
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLength.java b/core/src/main/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLength.java
index 2602353ea37..44d44585183 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLength.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLength.java
@@ -46,7 +46,7 @@
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.VarSymbol;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author epmjohnston@google.com (Emily P.M. Johnston)
@@ -101,8 +101,7 @@ private static boolean isValidTag(String tag) {
return Utf8.encodedLength(tag) <= 23;
}
- @Nullable
- private static VariableTree findEnclosingIdentifier(
+ private static @Nullable VariableTree findEnclosingIdentifier(
IdentifierTree originalNode, VisitorState state) {
Symbol identifierSymbol = getSymbol(originalNode);
if (!(identifierSymbol instanceof VarSymbol)) {
@@ -112,9 +111,8 @@ private static VariableTree findEnclosingIdentifier(
.findEnclosing(ClassTree.class)
.accept(
new TreeScanner() {
- @Nullable
@Override
- public VariableTree visitVariable(VariableTree node, Void p) {
+ public @Nullable VariableTree visitVariable(VariableTree node, Void p) {
return getSymbol(node).equals(identifierSymbol) ? node : null;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiffChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiffChecker.java
index 477fe922b50..f59064a7eb3 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiffChecker.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiffChecker.java
@@ -38,7 +38,7 @@
import com.sun.tools.javac.code.Types;
import java.lang.annotation.Annotation;
import java.util.Optional;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/** A base Error Prone check implementation to enforce compliance with a given API diff. */
public abstract class ApiDiffChecker extends BugChecker
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/EnclosedByReverseHeuristic.java b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/EnclosedByReverseHeuristic.java
index 54935fa59b6..29d37637af1 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/EnclosedByReverseHeuristic.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/EnclosedByReverseHeuristic.java
@@ -24,7 +24,7 @@
import com.sun.source.tree.Tree;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import java.util.Optional;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Detect whether the method invocation we are examining is enclosed by either a method or a class
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/LowInformationNameHeuristic.java b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/LowInformationNameHeuristic.java
index 1aa2adaedef..e0ba0c8f6cf 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/LowInformationNameHeuristic.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/LowInformationNameHeuristic.java
@@ -20,7 +20,7 @@
import com.google.errorprone.VisitorState;
import com.sun.source.tree.Tree;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* A heuristic for checking if a formal parameter matches a predefined set of words which have been
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java
index 59184c9956f..637756e9d66 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java
@@ -30,7 +30,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Extracts the necessary information from a {@link MethodInvocationTree} to check whether calls to
@@ -57,11 +57,9 @@ public abstract class AbstractCollectionIncompatibleTypeMatcher {
*
* @return the source type or null if not available
*/
- @Nullable
- abstract Type extractSourceType(MethodInvocationTree tree, VisitorState state);
+ abstract @Nullable Type extractSourceType(MethodInvocationTree tree, VisitorState state);
- @Nullable
- abstract Type extractSourceType(MemberReferenceTree tree, VisitorState state);
+ abstract @Nullable Type extractSourceType(MemberReferenceTree tree, VisitorState state);
/**
* Returns the AST node from which the source type was extracted. Needed to produce readable error
@@ -76,11 +74,10 @@ public abstract class AbstractCollectionIncompatibleTypeMatcher {
*
* @return the source AST node or null if not available
*/
- @Nullable
- abstract ExpressionTree extractSourceTree(MethodInvocationTree tree, VisitorState state);
+ abstract @Nullable ExpressionTree extractSourceTree(
+ MethodInvocationTree tree, VisitorState state);
- @Nullable
- abstract ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state);
+ abstract @Nullable ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state);
/**
* Extracts the target type to which the source type must be castable. For example, in this code
@@ -95,11 +92,9 @@ public abstract class AbstractCollectionIncompatibleTypeMatcher {
*
* @return the target type or null if not available
*/
- @Nullable
- abstract Type extractTargetType(MethodInvocationTree tree, VisitorState state);
+ abstract @Nullable Type extractTargetType(MethodInvocationTree tree, VisitorState state);
- @Nullable
- abstract Type extractTargetType(MemberReferenceTree tree, VisitorState state);
+ abstract @Nullable Type extractTargetType(MemberReferenceTree tree, VisitorState state);
/**
* Encapsulates the result of matching a {@link Collection#contains}-like call, including the
@@ -133,8 +128,7 @@ public Optional buildFix() {
}
}
- @Nullable
- public final MatchResult matches(ExpressionTree tree, VisitorState state) {
+ public final @Nullable MatchResult matches(ExpressionTree tree, VisitorState state) {
if (!methodMatcher().matches(tree, state)) {
return null;
}
@@ -160,8 +154,7 @@ public MatchResult visitMemberReference(
}.visit(tree, null);
}
- @Nullable
- private MatchResult getMatchResult(
+ private @Nullable MatchResult getMatchResult(
@Nullable ExpressionTree sourceTree, @Nullable Type sourceType, @Nullable Type targetType) {
if (sourceTree == null || sourceType == null || targetType == null) {
return null;
@@ -181,8 +174,7 @@ private MatchResult getMatchResult(
* @param types the {@link Types} utility class from the {@link VisitorState}
* @return the type argument, if defined, or null otherwise
*/
- @Nullable
- protected static Type extractTypeArgAsMemberOfSupertype(
+ protected static @Nullable Type extractTypeArgAsMemberOfSupertype(
Type type, Symbol superTypeSym, int typeArgIndex, Types types) {
Type collectionType = types.asSuper(type, superTypeSym);
if (collectionType == null) {
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/BinopMatcher.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/BinopMatcher.java
index e93467b5cf9..cb1ee07496b 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/BinopMatcher.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/BinopMatcher.java
@@ -25,7 +25,7 @@
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.code.Type;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
final class BinopMatcher extends AbstractCollectionIncompatibleTypeMatcher {
@@ -42,9 +42,8 @@ Matcher methodMatcher() {
return matcher;
}
- @Nullable
@Override
- Type extractSourceType(MethodInvocationTree tree, VisitorState state) {
+ @Nullable Type extractSourceType(MethodInvocationTree tree, VisitorState state) {
return extractTypeArgAsMemberOfSupertype(
getType(tree.getArguments().get(0)),
state.getSymbolFromString(collectionType),
@@ -52,9 +51,8 @@ Type extractSourceType(MethodInvocationTree tree, VisitorState state) {
state.getTypes());
}
- @Nullable
@Override
- Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
+ @Nullable Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
Type descriptorType = state.getTypes().findDescriptorType(getType(tree));
return extractTypeArgAsMemberOfSupertype(
descriptorType.getParameterTypes().get(0),
@@ -63,21 +61,18 @@ Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
state.getTypes());
}
- @Nullable
@Override
- ExpressionTree extractSourceTree(MethodInvocationTree tree, VisitorState state) {
+ @Nullable ExpressionTree extractSourceTree(MethodInvocationTree tree, VisitorState state) {
return tree.getArguments().get(0);
}
- @Nullable
@Override
- ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state) {
+ @Nullable ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state) {
return tree;
}
- @Nullable
@Override
- Type extractTargetType(MethodInvocationTree tree, VisitorState state) {
+ @Nullable Type extractTargetType(MethodInvocationTree tree, VisitorState state) {
return extractTypeArgAsMemberOfSupertype(
getType(tree.getArguments().get(1)),
state.getSymbolFromString(collectionType),
@@ -85,9 +80,8 @@ Type extractTargetType(MethodInvocationTree tree, VisitorState state) {
state.getTypes());
}
- @Nullable
@Override
- Type extractTargetType(MemberReferenceTree tree, VisitorState state) {
+ @Nullable Type extractTargetType(MemberReferenceTree tree, VisitorState state) {
Type descriptorType = state.getTypes().findDescriptorType(getType(tree));
return extractTypeArgAsMemberOfSupertype(
descriptorType.getParameterTypes().get(1),
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CompatibleWithMisuse.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CompatibleWithMisuse.java
index e81e5eedd47..c72fb33eebe 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CompatibleWithMisuse.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CompatibleWithMisuse.java
@@ -44,7 +44,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author glorioso@google.com (Nick Glorioso)
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/ContainmentMatchers.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/ContainmentMatchers.java
index ce6bd8e6d3c..53b837c59ff 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/ContainmentMatchers.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/ContainmentMatchers.java
@@ -22,7 +22,7 @@
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.matchers.Matchers;
import com.sun.source.tree.ExpressionTree;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Matchers for methods which express containment, like {@link java.util.Collection#contains}. */
public final class ContainmentMatchers {
@@ -106,8 +106,8 @@ public final class ContainmentMatchers {
.addAll(STATIC_MATCHERS)
.build();
- @Nullable
- public static MatchResult firstNonNullMatchResult(ExpressionTree tree, VisitorState state) {
+ public static @Nullable MatchResult firstNonNullMatchResult(
+ ExpressionTree tree, VisitorState state) {
if (!FIRST_ORDER_MATCHER.matches(tree, state)) {
return null;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java
index 2390babf1a0..d2699c8d354 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java
@@ -44,10 +44,10 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.lang.model.element.Parameterizable;
import javax.lang.model.element.TypeParameterElement;
+import org.jspecify.annotations.Nullable;
/**
* @author glorioso@google.com (Nick Glorioso)
@@ -68,8 +68,7 @@ public class IncompatibleArgumentType extends BugChecker implements MethodInvoca
// null requiredType: I found the type variable, but I can't bind it to any type
@AutoValue
abstract static class RequiredType {
- @Nullable
- abstract Type type();
+ abstract @Nullable Type type();
static RequiredType create(Type type) {
return new AutoValue_IncompatibleArgumentType_RequiredType(type);
@@ -206,10 +205,9 @@ private static boolean populateTypesToEnforce(
return foundAnyTypeToEnforce;
}
- @Nullable
- @CheckReturnValue
// From calledReceiverType
- private static RequiredType resolveRequiredTypeForThisCall(
+ @CheckReturnValue
+ private static @Nullable RequiredType resolveRequiredTypeForThisCall(
VisitorState state,
Type calledMethodType,
Type calledReceiverType,
@@ -226,8 +224,7 @@ private static RequiredType resolveRequiredTypeForThisCall(
return requiredType;
}
- @Nullable
- private static RequiredType resolveTypeFromGenericMethod(
+ private static @Nullable RequiredType resolveTypeFromGenericMethod(
Type calledMethodType, MethodSymbol declaredMethod, String typeArgName) {
int tyargIndex = findTypeArgInList(declaredMethod, typeArgName);
return tyargIndex == -1
@@ -238,8 +235,7 @@ private static RequiredType resolveTypeFromGenericMethod(
// Plumb through a type which is supposed to be a Types.Subst, then find the replacement
// type that the compiler resolved.
- @Nullable
- private static Type getTypeFromTypeMapping(
+ private static @Nullable Type getTypeFromTypeMapping(
Type m, MethodSymbol declaredMethod, String namedTypeArg) {
ImmutableListMultimap substitutions =
ASTHelpers.getTypeSubstitution(m, declaredMethod);
@@ -254,8 +250,7 @@ private static Type getTypeFromTypeMapping(
// class Foo { void something(@CW("X") Object x); }
// new Foo().something(123);
- @Nullable
- private static RequiredType resolveTypeFromClass(
+ private static @Nullable RequiredType resolveTypeFromClass(
Type calledType, ClassSymbol clazzSymbol, String typeArgName, VisitorState state) {
// Try on the class
int tyargIndex = findTypeArgInList(clazzSymbol, typeArgName);
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/MethodArgMatcher.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/MethodArgMatcher.java
index bac06dadb3b..5f5df71b7ca 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/MethodArgMatcher.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/MethodArgMatcher.java
@@ -31,7 +31,7 @@
import com.sun.tools.javac.code.Type;
import java.util.Collection;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Matches an instance method like {@link Collection#contains}, for which we just need to compare
@@ -67,9 +67,8 @@ ExpressionTree extractSourceTree(MethodInvocationTree tree, VisitorState state)
return Iterables.get(tree.getArguments(), methodArgIndex);
}
- @Nullable
@Override
- ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state) {
+ @Nullable ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state) {
return tree;
}
@@ -78,9 +77,8 @@ Type extractSourceType(MethodInvocationTree tree, VisitorState state) {
return getType(extractSourceTree(tree, state));
}
- @Nullable
@Override
- Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
+ @Nullable Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
return state.getTypes().findDescriptorType(getType(tree)).getParameterTypes().get(0);
}
@@ -93,9 +91,8 @@ Type extractTargetType(MethodInvocationTree tree, VisitorState state) {
state.getTypes());
}
- @Nullable
@Override
- Type extractTargetType(MemberReferenceTree tree, VisitorState state) {
+ @Nullable Type extractTargetType(MemberReferenceTree tree, VisitorState state) {
return extractTypeArgAsMemberOfSupertype(
ASTHelpers.getReceiverType(tree),
state.getSymbolFromString(typeName),
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TypeArgOfMethodArgMatcher.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TypeArgOfMethodArgMatcher.java
index 1092422294a..e78e11dbaf8 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TypeArgOfMethodArgMatcher.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TypeArgOfMethodArgMatcher.java
@@ -33,7 +33,7 @@
import com.sun.tools.javac.code.Type;
import java.util.Collection;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* Matches an instance method like {@link Collection#removeAll}, for which we need to extract the
@@ -84,9 +84,8 @@ ExpressionTree extractSourceTree(MethodInvocationTree tree, VisitorState state)
return Iterables.get(tree.getArguments(), methodArgIndex);
}
- @Nullable
@Override
- ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state) {
+ @Nullable ExpressionTree extractSourceTree(MemberReferenceTree tree, VisitorState state) {
return tree;
}
@@ -99,9 +98,8 @@ Type extractSourceType(MethodInvocationTree tree, VisitorState state) {
state.getTypes());
}
- @Nullable
@Override
- Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
+ @Nullable Type extractSourceType(MemberReferenceTree tree, VisitorState state) {
return extractTypeArgAsMemberOfSupertype(
getType(tree).allparams().get(methodArgIndex),
state.getSymbolFromString(methodArgTypeName),
@@ -118,9 +116,8 @@ Type extractTargetType(MethodInvocationTree tree, VisitorState state) {
state.getTypes());
}
- @Nullable
@Override
- Type extractTargetType(MemberReferenceTree tree, VisitorState state) {
+ @Nullable Type extractTargetType(MemberReferenceTree tree, VisitorState state) {
return extractTypeArgAsMemberOfSupertype(
ASTHelpers.getReceiverType(tree),
state.getSymbolFromString(receiverTypeName),
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerArgumentToString.java b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerArgumentToString.java
index 08e0a325c0e..62c00eb1b46 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerArgumentToString.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerArgumentToString.java
@@ -49,8 +49,8 @@
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
-import javax.annotation.Nullable;
import javax.lang.model.type.TypeKind;
+import org.jspecify.annotations.Nullable;
/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
@@ -106,7 +106,7 @@ static class Parameter {
final Supplier source;
final Type type;
- @Nullable final Character placeholder;
+ final @Nullable Character placeholder;
private Parameter(ExpressionTree expression, char placeholder) {
this(s -> s.getSourceForNode(expression), getType(expression), placeholder);
@@ -355,8 +355,8 @@ Description unwrapArguments(
return describeMatch(tree, fix.build());
}
- @Nullable
- private static Parameter unwrap(ExpressionTree argument, char placeholder, VisitorState state) {
+ private static @Nullable Parameter unwrap(
+ ExpressionTree argument, char placeholder, VisitorState state) {
for (Unwrapper unwrapper : Unwrapper.values()) {
if (unwrapper.matcher.matches(argument, state)) {
return unwrapper.unwrap((MethodInvocationTree) argument, placeholder);
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerFormatString.java b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerFormatString.java
index 2319851d42d..0368ea82cb6 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerFormatString.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerFormatString.java
@@ -37,7 +37,7 @@
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import java.util.List;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author cushon@google.com (Liam Miller-Cushon)
@@ -83,8 +83,8 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
* If there were more arguments than format specifiers and the last argument is an exception,
* suggest using {@code withCause(e)} instead of adding a format specifier.
*/
- @Nullable
- private Fix withCauseFix(ValidationResult result, MethodInvocationTree tree, VisitorState state) {
+ private @Nullable Fix withCauseFix(
+ ValidationResult result, MethodInvocationTree tree, VisitorState state) {
if (!result.message().startsWith("extra format arguments")) {
return null;
}
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabled.java b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabled.java
index 11e1cacaa3c..03cadac121f 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabled.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabled.java
@@ -47,7 +47,7 @@
import com.sun.tools.javac.code.Symbol;
import java.util.List;
import java.util.Optional;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jspecify.annotations.Nullable;
/**
* @author mariasam@google.com (Maria Sam)
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerWithoutCause.java b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerWithoutCause.java
index 07f99a4b7a5..d5649146f45 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerWithoutCause.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerWithoutCause.java
@@ -32,8 +32,8 @@
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.code.Type;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.annotation.Nullable;
import javax.lang.model.type.TypeKind;
+import org.jspecify.annotations.Nullable;
/**
* Detects Flogger log statements that pass Exceptions to the log method instead of using withCause.
@@ -84,8 +84,7 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void unused) {
String.format(".withCause(%s)", state.getSourceForNode(exception))));
}
- @Nullable
- private static Tree getExceptionArg(MethodInvocationTree tree, VisitorState state) {
+ private static @Nullable Tree getExceptionArg(MethodInvocationTree tree, VisitorState state) {
for (Tree arg : Lists.reverse(tree.getArguments())) {
try {
Type argType = ASTHelpers.getType(arg);
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java b/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java
index 732be68b862..b4c855f70ab 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java
@@ -60,8 +60,8 @@
import java.util.UnknownFormatFlagsException;
import java.util.stream.IntStream;
import java.util.stream.Stream;
-import javax.annotation.Nullable;
import javax.lang.model.type.TypeKind;
+import org.jspecify.annotations.Nullable;
/** Utilities for validating format strings. */
public final class FormatStringValidation {
@@ -96,8 +96,7 @@ protected Void defaultAction(Tree tree, Void unused) {
return flat.stream().map(t -> ASTHelpers.constValue(t, String.class)).filter(x -> x != null);
}
- @Nullable
- public static ValidationResult validate(
+ public static @Nullable ValidationResult validate(
@Nullable MethodSymbol formatMethodSymbol,
Collection extends ExpressionTree> arguments,
VisitorState state) {
@@ -149,8 +148,7 @@ public static ValidationResult validate(
* For example, an intance of {@link Integer} will be returned for an input of type {@code int} or
* {@link Integer}.
*/
- @Nullable
- private static Object getInstance(Tree tree, VisitorState state) {
+ private static @Nullable Object getInstance(Tree tree, VisitorState state) {
Object value = ASTHelpers.constValue(tree);
if (value != null) {
return value;
@@ -159,8 +157,7 @@ private static Object getInstance(Tree tree, VisitorState state) {
return getInstance(type, state);
}
- @Nullable
- private static Object getInstance(Type type, VisitorState state) {
+ private static @Nullable Object getInstance(Type type, VisitorState state) {
Types types = state.getTypes();
if (type.getKind() == TypeKind.NULL) {
return null;
@@ -282,8 +279,7 @@ private static ValidationResult validate(String formatString, Object[] arguments
return extraFormatArguments(formatString, asList(arguments));
}
- @Nullable
- private static ValidationResult extraFormatArguments(
+ private static @Nullable ValidationResult extraFormatArguments(
String formatString, List