Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions nullaway/src/main/java/com/uber/nullaway/LibraryModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MethodRef, Integer> 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.
* <p>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.
Expand All @@ -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.
* <p>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
Expand All @@ -74,16 +74,16 @@ public interface LibraryModels {
/**
* Get (method, parameter) pairs that cause the method to return <code>true</code> 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<MethodRef, Integer> nullImpliesTrueParameters();

/**
* Get (method, parameter) pairs that cause the method to return <code>false</code> 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<MethodRef, Integer> nullImpliesFalseParameters();

Expand All @@ -108,8 +108,11 @@ default ImmutableSetMultimap<MethodRef, MethodRef> ensuresNonNullIfTrueMethodCal
*
* <pre><code>@Contract("!null -&gt; !null") @Nullable</code></pre>
*
* @return map from the names of null-in-implies-null out methods to the indexes of the arguments
* that determine nullness of the return.
* <p>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<MethodRef, Integer> nullImpliesNullParameters();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading