@@ -316,7 +316,7 @@ public NullAway(ErrorProneFlags flags) {
316316 genericsChecks = new GenericsChecks (this , config , handler );
317317 }
318318
319- public boolean isMethodUnannotated (MethodInvocationNode invocationNode ) {
319+ public boolean isMethodUnannotated (@ Nullable MethodInvocationNode invocationNode ) {
320320 return invocationNode == null
321321 || codeAnnotationInfo .isSymbolUnannotated (
322322 ASTHelpers .getSymbol (invocationNode .getTree ()), config , handler );
@@ -518,9 +518,8 @@ public Description matchAssignment(AssignmentTree tree, VisitorState state) {
518518 genericsChecks .checkTypeParameterNullnessForAssignability (tree , state );
519519 }
520520
521- if (config .isJSpecifyMode () && tree .getVariable () instanceof ArrayAccessTree ) {
521+ if (config .isJSpecifyMode () && tree .getVariable () instanceof ArrayAccessTree arrayAccess ) {
522522 // check for a write of a @Nullable value into @NonNull array contents
523- ArrayAccessTree arrayAccess = (ArrayAccessTree ) tree .getVariable ();
524523 ExpressionTree arrayExpr = arrayAccess .getExpression ();
525524 ExpressionTree expression = tree .getExpression ();
526525 Symbol arraySymbol = ASTHelpers .getSymbol (arrayExpr );
@@ -856,7 +855,7 @@ private Description checkParamOverriding(
856855 + "functional interface method "
857856 + ASTHelpers .enclosingClass (overriddenMethod )
858857 + "."
859- + overriddenMethod . toString ()
858+ + overriddenMethod
860859 + " is @Nullable" ;
861860 return errorBuilder .createErrorDescription (
862861 new ErrorMessage (MessageTypes .WRONG_OVERRIDE_PARAM , message ),
@@ -898,7 +897,7 @@ private Description checkParamOverriding(
898897 + "method "
899898 + ASTHelpers .enclosingClass (overriddenMethod )
900899 + "."
901- + overriddenMethod . toString ()
900+ + overriddenMethod
902901 + " is @Nullable" ;
903902 Tree errorTree ;
904903 if (memberReferenceTree != null ) {
@@ -1109,14 +1108,14 @@ && getMethodReturnNullness(overridingMethod, state, Nullness.NONNULL)
11091108 "referenced method returns @Nullable, but functional interface method "
11101109 + ASTHelpers .enclosingClass (overriddenMethod )
11111110 + "."
1112- + overriddenMethod . toString ()
1111+ + overriddenMethod
11131112 + " returns @NonNull" ;
11141113 } else {
11151114 message =
11161115 "method returns @Nullable, but superclass method "
11171116 + ASTHelpers .enclosingClass (overriddenMethod )
11181117 + "."
1119- + overriddenMethod . toString ()
1118+ + overriddenMethod
11201119 + " returns @NonNull" ;
11211120 }
11221121
@@ -1375,7 +1374,7 @@ private ImmutableSet<Element> safeInitByCalleeBefore(
13751374 if (curStmt instanceof TryTree tryTree ) {
13761375 // ToDo: Should we check initialization inside tryTree.getResources ? What is the scope of
13771376 // that initialization?
1378- if (tryTree .getCatches ().size () == 0 ) {
1377+ if (tryTree .getCatches ().isEmpty () ) {
13791378 if (tryTree .getBlock () != null ) {
13801379 resultBuilder .addAll (
13811380 safeInitByCalleeBefore (
@@ -1458,7 +1457,7 @@ private ImmutableMultimap<Tree, Element> computeTree2Init(
14581457 }
14591458 }
14601459 // all the initializer blocks have run before any code inside a constructor
1461- constructors .stream (). forEach ((c ) -> builder .putAll (c , initThusFar ));
1460+ constructors .forEach ((c ) -> builder .putAll (c , initThusFar ));
14621461 Symbol .ClassSymbol classSymbol = ASTHelpers .getSymbol (enclosingClass );
14631462 FieldInitEntities entities = castToNonNull (class2Entities .get (classSymbol ));
14641463 if (entities .instanceInitializerMethods ().size () == 1 ) {
@@ -1506,7 +1505,7 @@ private boolean okToReadBeforeInitialized(TreePath path, VisitorState state) {
15061505 // ok if it's invoking castToNonNull and the read is the argument
15071506 Symbol .MethodSymbol methodSymbol = ASTHelpers .getSymbol (methodInvoke );
15081507 String qualifiedName =
1509- ASTHelpers .enclosingClass (methodSymbol ) + "." + methodSymbol .getSimpleName (). toString () ;
1508+ ASTHelpers .enclosingClass (methodSymbol ) + "." + methodSymbol .getSimpleName ();
15101509 List <? extends ExpressionTree > arguments = methodInvoke .getArguments ();
15111510 Integer castToNonNullArg ;
15121511 if (qualifiedName .equals (config .getCastToNonNullMethod ())
@@ -1517,10 +1516,7 @@ private boolean okToReadBeforeInitialized(TreePath path, VisitorState state) {
15171516 handler .castToNonNullArgumentPositionsForMethod (
15181517 arguments , null , new MethodAnalysisContext (this , state , methodSymbol ));
15191518 }
1520- if (castToNonNullArg != null && leaf .equals (arguments .get (castToNonNullArg ))) {
1521- return true ;
1522- }
1523- return false ;
1519+ return castToNonNullArg != null && leaf .equals (arguments .get (castToNonNullArg ));
15241520 }
15251521 return false ;
15261522 }
@@ -2034,7 +2030,7 @@ private Description checkCastToNonNullTakesNullable(
20342030 Symbol .MethodSymbol methodSymbol ,
20352031 List <? extends ExpressionTree > actualParams ) {
20362032 String qualifiedName =
2037- ASTHelpers .enclosingClass (methodSymbol ) + "." + methodSymbol .getSimpleName (). toString () ;
2033+ ASTHelpers .enclosingClass (methodSymbol ) + "." + methodSymbol .getSimpleName ();
20382034 Integer castToNonNullPosition ;
20392035 if (qualifiedName .equals (config .getCastToNonNullMethod ())
20402036 && methodSymbol .getParameters ().size () == 1 ) {
@@ -2055,8 +2051,7 @@ private Description checkCastToNonNullTakesNullable(
20552051 throw new RuntimeException ("no enclosing method, lambda or initializer!" );
20562052 } else if (enclosingMethodOrLambda .getLeaf () instanceof LambdaExpressionTree ) {
20572053 isInitializer = false ;
2058- } else if (enclosingMethodOrLambda .getLeaf () instanceof MethodTree ) {
2059- MethodTree enclosingMethod = (MethodTree ) enclosingMethodOrLambda .getLeaf ();
2054+ } else if (enclosingMethodOrLambda .getLeaf () instanceof MethodTree enclosingMethod ) {
20602055 isInitializer = isInitializerMethod (state , ASTHelpers .getSymbol (enclosingMethod ));
20612056 } else {
20622057 // Initializer block
@@ -2239,7 +2234,7 @@ private SetMultimap<MethodTree, Symbol> checkConstructorInitialization(
22392234 if (constructorInvokesAnother (constructor , state )) {
22402235 continue ;
22412236 }
2242- if (constructor .getParameters ().size () == 0
2237+ if (constructor .getParameters ().isEmpty ()
22432238 && (isExternalInitClass
22442239 || symbolHasExternalInitAnnotation (ASTHelpers .getSymbol (constructor )))) {
22452240 // external framework initializes fields in this case
@@ -2281,18 +2276,16 @@ private ImmutableSet<Element> guaranteedNonNullForConstructor(
22812276 private boolean constructorInvokesAnother (MethodTree constructor , VisitorState state ) {
22822277 BlockTree body = constructor .getBody ();
22832278 List <? extends StatementTree > statements = body .getStatements ();
2284- if (statements .size () > 0 ) {
2279+ if (! statements .isEmpty () ) {
22852280 StatementTree statementTree = statements .get (0 );
2286- if (isThisCall (statementTree , state )) {
2287- return true ;
2288- }
2281+ return isThisCall (statementTree , state );
22892282 }
22902283 return false ;
22912284 }
22922285
22932286 private Set <Symbol > notInitializedStatic (FieldInitEntities entities , VisitorState state ) {
22942287 ImmutableSet <Symbol > nonNullStaticFields = entities .nonnullStaticFields ();
2295- Set <Element > initializedInStaticInitializers = new LinkedHashSet <Element >();
2288+ Set <Element > initializedInStaticInitializers = new LinkedHashSet <>();
22962289 AccessPathNullnessAnalysis nullnessAnalysis = getNullnessAnalysis (state );
22972290 for (BlockTree initializer : entities .staticInitializerBlocks ()) {
22982291 Set <Element > nonnullAtExit =
@@ -2306,7 +2299,7 @@ private Set<Symbol> notInitializedStatic(FieldInitEntities entities, VisitorStat
23062299 new TreePath (state .getPath (), initializerMethod ), state .context );
23072300 initializedInStaticInitializers .addAll (nonnullAtExit );
23082301 }
2309- Set <Symbol > notInitializedStaticFields = new LinkedHashSet <Symbol >();
2302+ Set <Symbol > notInitializedStaticFields = new LinkedHashSet <>();
23102303 for (Symbol field : nonNullStaticFields ) {
23112304 if (!initializedInStaticInitializers .contains (field )) {
23122305 notInitializedStaticFields .add (field );
@@ -2349,7 +2342,7 @@ private Set<Element> getSafeInitMethods(
23492342 // there is also an
23502343 // exception of the full method.
23512344 if (stmt instanceof TryTree tryTree ) {
2352- if (tryTree .getCatches ().size () == 0 ) {
2345+ if (tryTree .getCatches ().isEmpty () ) {
23532346 if (tryTree .getBlock () != null ) {
23542347 result .addAll (getSafeInitMethods (tryTree .getBlock (), classSymbol , state ));
23552348 }
@@ -2683,12 +2676,10 @@ private boolean mayBeNullMethodCall(
26832676 "%s not found as a descendant of %s" ,
26842677 invocationTree ,
26852678 path .getLeaf ());
2686- if ( genericsChecks
2679+ return genericsChecks
26872680 .getGenericReturnNullnessAtInvocation (
26882681 exprSymbol , invocationTree , invocationPath , state , false )
2689- .equals (Nullness .NULLABLE )) {
2690- return true ;
2691- }
2682+ .equals (Nullness .NULLABLE );
26922683 }
26932684 return false ;
26942685 }
0 commit comments