@@ -666,8 +666,7 @@ private Type substituteInferredNullabilityForTypeVariables(
666666 for (Type .TypeVar tv : tvc .getMatches ()) {
667667 typeVars .append (tv );
668668 inferredTypes .append (
669- TypeSubstitutionUtils .typeWithAnnot (
670- tv , GenericsChecks .getSyntheticNullAnnotType (state )));
669+ TypeSubstitutionUtils .typeWithAnnot (tv , getSyntheticNullAnnotType (state )));
671670 }
672671 }
673672 }
@@ -1449,6 +1448,8 @@ public boolean isNullableAnnotated(Type type) {
14491448 return Nullness .hasNullableAnnotation (type .getAnnotationMirrors ().stream (), config );
14501449 }
14511450
1451+ private @ Nullable Type syntheticNullAnnotType ;
1452+
14521453 /**
14531454 * Returns a "fake" {@link Type} object representing a synthetic {@code @Nullable} annotation.
14541455 *
@@ -1462,12 +1463,15 @@ public boolean isNullableAnnotated(Type type) {
14621463 * Symtab}.
14631464 * @return a fake {@code Type} for a synthetic {@code @Nullable} annotation.
14641465 */
1465- public static Type getSyntheticNullAnnotType (VisitorState state ) {
1466- Names names = Names .instance (state .context );
1467- Symtab symtab = Symtab .instance (state .context );
1468- Name name = names .fromString ("nullaway.synthetic" );
1469- Symbol .PackageSymbol packageSymbol = new Symbol .PackageSymbol (name , symtab .noSymbol );
1470- Name simpleName = names .fromString ("Nullable" );
1471- return new Type .ErrorType (simpleName , packageSymbol , Type .noType );
1466+ public Type getSyntheticNullAnnotType (VisitorState state ) {
1467+ if (syntheticNullAnnotType == null ) {
1468+ Names names = Names .instance (state .context );
1469+ Symtab symtab = Symtab .instance (state .context );
1470+ Name name = names .fromString ("nullaway.synthetic" );
1471+ Symbol .PackageSymbol packageSymbol = new Symbol .PackageSymbol (name , symtab .noSymbol );
1472+ Name simpleName = names .fromString ("Nullable" );
1473+ syntheticNullAnnotType = new Type .ErrorType (simpleName , packageSymbol , Type .noType );
1474+ }
1475+ return syntheticNullAnnotType ;
14721476 }
14731477}
0 commit comments