with `@Contract("null, _ -> fail")`. With that contract declaration, NullAway will understand that the value passed as a
which is annotated with `@Contract("null, _ -> fail")`. With that contract declaration, NullAway will understand
parameter cannot be null after a successful invocation of `Assert.notNull()`.
that the value passed as a parameter cannot be null after a successful invocation of `Assert.notNull()`.
Optionally, it is possible to set `NullAway:JSpecifyMode=true` to enable
Optionally, it is possible to set `NullAway:JSpecifyMode=true` to enable
https://github.com/uber/NullAway/wiki/JSpecify-Support[checks on the full JSpecify semantics], including annotations on
https://github.com/uber/NullAway/wiki/JSpecify-Support[checks on the full JSpecify semantics], including annotations on
@ -160,8 +163,8 @@ generates no warning with the recommended configuration mentioned previously in
==== Warnings suppression
==== Warnings suppression
There are a few valid use cases where NullAway will incorrectly detect nullability problems. In such cases, it is recommended
There are a few valid use cases where NullAway will incorrectly detect nullability problems. In such cases,
to suppress related warnings and to document the reason:
it is recommended to suppress related warnings and to document the reason:
- `@SuppressWarnings("NullAway.Init")` at field, constructor, or class level can be used to avoid unnecessary warnings
- `@SuppressWarnings("NullAway.Init")` at field, constructor, or class level can be used to avoid unnecessary warnings
due to the lazy initialization of fields – for example, due to a class implementing
due to the lazy initialization of fields – for example, due to a class implementing
@ -172,8 +175,8 @@ able to detect that the path involving a nullability problem will never happen.
outside of a lambda for the code path within the lambda.
outside of a lambda for the code path within the lambda.
- `@SuppressWarnings("NullAway") // Reflection` can be used for some reflection operations that are known to return
- `@SuppressWarnings("NullAway") // Reflection` can be used for some reflection operations that are known to return
non-null values even if that cannot be expressed by the API.
non-null values even if that cannot be expressed by the API.
- `@SuppressWarnings("NullAway") // Well-known map keys` can be used when `Map#get` invocations are performed with keys that are known
- `@SuppressWarnings("NullAway") // Well-known map keys` can be used when `Map#get` invocations are performed with keys
to be present and when non-null related values have been inserted previously.
that are known to be present and when non-null related values have been inserted previously.
- `@SuppressWarnings("NullAway") // Overridden method does not define nullability` can be used when the superclass does
- `@SuppressWarnings("NullAway") // Overridden method does not define nullability` can be used when the superclass does
not define nullability (typically when the superclass comes from an external dependency).
not define nullability (typically when the superclass comes from an external dependency).
- `@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075` can be used when NullAway is not able to detect type variable nullness in generic methods.
- `@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1075` can be used when NullAway is not able to detect type variable nullness in generic methods.
@ -208,7 +211,6 @@ with JSpecify annotations.
- For method return types, instead of `@Nullable public String method()` with Spring annotations, use
- For method return types, instead of `@Nullable public String method()` with Spring annotations, use
`public @Nullable String method()` with JSpecify annotations.
`public @Nullable String method()` with JSpecify annotations.
Also, with JSpecify, you do not need to specify `@NonNull` when overriding a type usage annotated with `@Nullable` in the
Also, with JSpecify, you do not need to specify `@NonNull` when overriding a type usage annotated with `@Nullable`
super method to "undo" the nullable declaration in null-marked code. Just declare it unannotated, and the null-marked
in the super method to "undo" the nullable declaration in null-marked code. Just declare it unannotated, and the
defaults will apply (type usage is considered non-null unless explicitly annotated as nullable).
null-marked defaults will apply (type usage is considered non-null unless explicitly annotated as nullable).