Skip to content

Commit 75c613f

Browse files
committed
coderabbit review suggestions
1 parent 84f9fe9 commit 75c613f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

nullaway/src/main/java/com/uber/nullaway/generics/TypeVarWithSymbolCollector.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public TypeVarWithSymbolCollector(Element symbol) {
3030
this.symbol = symbol;
3131
}
3232

33+
private final Set<Type> seen =
34+
java.util.Collections.newSetFromMap(new java.util.IdentityHashMap<>());
35+
3336
/** Walk a (possibly null) type. Safe to call multiple times on different roots. */
3437
private void scan(@Nullable Type t) {
35-
if (t != null) {
38+
if (t != null && seen.add(t)) {
3639
t.accept(this, null);
3740
}
3841
}

0 commit comments

Comments
 (0)