diff --git a/nullaway/src/main/java/com/uber/nullaway/LibraryModels.java b/nullaway/src/main/java/com/uber/nullaway/LibraryModels.java index 2f4642a9f9..9f84df1746 100644 --- a/nullaway/src/main/java/com/uber/nullaway/LibraryModels.java +++ b/nullaway/src/main/java/com/uber/nullaway/LibraryModels.java @@ -42,16 +42,16 @@ public interface LibraryModels { /** * Get methods which fail/error out when passed null. * - * @return map from the names of null-rejecting methods to the indexes of the arguments that - * aren't permitted to be null. + * @return map from null-rejecting methods to the indexes of the arguments that aren't permitted + * to be null. */ ImmutableSetMultimap failIfNullParameters(); /** * Get (method, parameter) pairs that must be modeled as if explicitly annotated with @Nullable. * - * @return map from the names of methods with @Nullable parameters to the indexes of the arguments - * that are @Nullable. + * @return map from methods with @Nullable parameters to the indexes of the arguments that + * are @Nullable. *

This is taken into account for override checks, requiring methods that override the * methods listed here to take @Nullable parameters on the same indexes. The main use for this * is to document which API callbacks can be passed null values. @@ -61,8 +61,8 @@ public interface LibraryModels { /** * Get (method, parameter) pairs that must be modeled as @NonNull. * - * @return map from the names of methods with @NonNull parameters to the indexes of the arguments - * that are @NonNull. + * @return map from methods with @NonNull parameters to the indexes of the arguments that + * are @NonNull. *

Note that these methods are different from the {@link #failIfNullParameters()} methods, * in that we expect the null checker to ensure that the parameters passed to these methods * are @NonNull. In contrast, the null checker does no such enforcement for methods in {@link @@ -74,16 +74,16 @@ public interface LibraryModels { /** * Get (method, parameter) pairs that cause the method to return true when null. * - * @return map from the names of null-querying methods to the indexes of the arguments that are - * compared against null. + * @return map from null-querying methods to the indexes of the arguments that are compared + * against null. */ ImmutableSetMultimap nullImpliesTrueParameters(); /** * Get (method, parameter) pairs that cause the method to return false when null. * - * @return map from the names of non-null-querying methods to the indexes of the arguments that - * are compared against null. + * @return map from non-null-querying methods to the indexes of the arguments that are compared + * against null. */ ImmutableSetMultimap nullImpliesFalseParameters(); @@ -108,8 +108,11 @@ default ImmutableSetMultimap ensuresNonNullIfTrueMethodCal * *

@Contract("!null -> !null") @Nullable
* - * @return map from the names of null-in-implies-null out methods to the indexes of the arguments - * that determine nullness of the return. + *

The model applies to any method that overrides the listed method. NullAway does not check + * that such an override obeys the contract (issue #803). + * + * @return map from null-in-implies-null-out methods to the indexes of the arguments that + * determine nullness of the return. */ ImmutableSetMultimap nullImpliesNullParameters(); diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java b/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java index 17566f2054..b28aa96034 100644 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java +++ b/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java @@ -226,11 +226,11 @@ public boolean onOverrideMayBeNullExpr( return exprMayBeNull; } OptimizedLibraryModels optLibraryModels = getOptLibraryModels(state.context); - // When looking up library models of annotated code, we match the exact method signature only; - // overriding methods in subclasses must be explicitly given their own library model. - // When dealing with unannotated code, we default to generality: a model applies to a method - // and any of its overriding implementations. - // see https://github.com/uber/NullAway/issues/445 for why this is needed. + // A model of a method's return nullness matches the exact signature when the method is + // annotated: the overriding method carries its own annotations, and an inherited model must + // not override them (issue #445). Unannotated code has no annotations to defer to, so there a + // model covers every overriding implementation. A nullImpliesNull model is a conditional + // contract, and applies to an overriding implementation in annotated code too. boolean isMethodUnannotated = getCodeAnnotationInfo(state.context) .isSymbolUnannotated(methodSymbol, this.config, mainHandler);