Nullability
Composite Recipes
Recipes that include further recipes, often including the individual recipes below.
Recipes
- Add
@MonotonicNonNullto a lazily-initialized field - Add
@MonotonicNonNullto an uninitialized field - Add
@NullMarkedto every package - Add
@NullMarkedtopackage-info.javafor an allowlist of packages - Add
@Nullableto Java returns from Kotlin call sites - Add
@Nullableto a field assigned a nullable value - Add
@Nullableto a functional-interface return type argument fed a null-returning lambda - Add
@Nullableto a method that can return null - Add
@Nullableto a mismatched generic type argument - Add
@Nullableto array element types that can hold null - Add
@Nullableto collection and map type arguments that hold null elements - Add
@Nullableto fields that can hold null - Add
@Nullableto generated Thrift getters ofoptionalfields - Add
@Nullableto method parameters that can receive null - Add
@Nullableto methods that can return null - Add a
@Contractnullness contract to a validation helper - Add a
@Nullableupper bound to a pass-through type parameter fed a null-returning lambda - Align override nullability with the supertype
- Extract a repeated
@Nullableinvocation into a local variable - Hoist a guarded
@Nullablefield read into a local variable - Make a nullable
Booleancondition null-safe withBoolean.TRUE.equals(...) - Migrate
@NonNullApi/ParametersAreNonnullByDefaultto JSpecify@NullMarked - Move a leading
@Nullableto the type-use position - Propagate
@Nullableacross override relationships - Relax
Optional.oftoOptional.ofNullableon nullable values - Relocate a misplaced leading
@Nullableon a primitive array to the array reference - Remove a provably-dead
if (x == null)guard - Remove a redundant
@NonNullannotation under@NullMarked - Remove a redundant declaration-position
@Nullableon a method return - Replace
@Nullablewith@MonotonicNonNullon a lazily-initialized field - Replace nullable
x.toString()withString.valueOf(x) - Return an empty collection instead of
null - Route a guarded raw accessor through its present
Optional - Wrap a nullable for-each iterable in
requireNonNull - Wrap nullable arguments passed to non-null parameters in
requireNonNull - Wrap nullable dereferenced values in
requireNonNull - Wrap nullable
switchselectors inrequireNonNull - Wrap nullable thrown expressions in
requireNonNull - Wrap nullable values that are auto-unboxed in
requireNonNull