Skip to content

Commit

Permalink
Fix incorrect wildcard/inner type handling in JSpecify mode
Browse files Browse the repository at this point in the history
  • Loading branch information
armughan11 committed Oct 19, 2023
1 parent f1ba82a commit 4bdd570
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ private static boolean isDirectTypeUseAnnotation(Attribute.TypeCompound t, Confi
// proper deprecation of the incorrect behaviors for type use annotations when their
// semantics don't match those of a declaration annotation in the same position.
// See https://github.com/uber/NullAway/issues/708
if (config.isJSpecifyMode()) {
return isDirectTypeUseAnnotationJSpecify(t);
}

boolean locationHasInnerTypes = false;
boolean locationHasArray = false;
for (TypePathEntry entry : t.position.location) {
Expand All @@ -319,6 +317,11 @@ private static boolean isDirectTypeUseAnnotation(Attribute.TypeCompound t, Confi
locationHasInnerTypes = true;
break;
case ARRAY:
// Currently we are ignoring @Nullable annotations on type in JSpecify mode.
// Eventually, this should return true if annotation is on type.
if (config.isJSpecifyMode()) {
return false;
}
locationHasArray = true;
break;
default:
Expand All @@ -330,12 +333,6 @@ private static boolean isDirectTypeUseAnnotation(Attribute.TypeCompound t, Confi
return !(locationHasInnerTypes && locationHasArray);
}

private static boolean isDirectTypeUseAnnotationJSpecify(Attribute.TypeCompound t) {
// Currently we are ignoring @Nullable annotations on type in JSpecify mode.
// Eventually, this should return true if annotation is on type.
return t.position.location.isEmpty();
}

/**
* Check if a field might be null, based on the type.
*
Expand Down

0 comments on commit 4bdd570

Please sign in to comment.