From 4bdd570ba0738ded79aef3294a69d9a569486861 Mon Sep 17 00:00:00 2001 From: Md Date: Wed, 18 Oct 2023 17:50:42 -0700 Subject: [PATCH] Fix incorrect wildcard/inner type handling in JSpecify mode --- .../java/com/uber/nullaway/NullabilityUtil.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java b/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java index b78c1f25ad..4d5aa84e5b 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java @@ -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) { @@ -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: @@ -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. *