org.springframework.data.util

## Class NullableUtils

- java.lang.Object
- - org.springframework.data.util.NullableUtils

    public abstract class NullableUtils
    extends Object

Utility methods to introspect nullability rules declared in packages, classes and methods.

Nullability rules are declared using `NonNullApi` and `Nullable` and JSR-305 `Nonnull` annotations. By default (no annotation use), a package and its types are considered allowing null values in return values and method parameters. Nullability rules are expressed by annotating a package with a JSR-305 meta annotation such as Spring's `NonNullApi`. All types of the package inherit the package rule. Subpackages do not inherit nullability rules and must be annotated themself.

     @org.springframework.lang.NonNullApi
     package com.example;

`Nullable` selectively permits null values for method return values or method parameters by annotating the method respectively the parameters:

     public class ExampleClass {

            String shouldNotReturnNull(@Nullable String acceptsNull, String doesNotAcceptNull) {
                    // …
            }

            @Nullable
            String nullableReturn(String parameter) {
                    // …
            }
     }

`Nonnull` is suitable for composition of meta-annotations and expresses via `Nonnull.when()` in which cases non-nullability is applicable.

Since:
  2.0
Author:
  Mark Paluch
See Also:
  `NonNullApi`, `Nullable`, `Nonnull`

### Method Summary

All Methods Static Methods Concrete Methods
`static boolean` `isExplicitNullable(MethodParameter methodParameter)` Determine whether a `MethodParameter` is explicitly annotated to be considered nullable.
`static boolean` `isNonNull(AnnotatedElement element, ElementType elementType)` Determine whether `ElementType` in the scope of `AnnotatedElement` requires non-null values.
`static boolean` `isNonNull(Class<?> type, ElementType elementType)` Determine whether `ElementType` in the scope of `type` requires non-null values.
`static boolean` `isNonNull(Method method, ElementType elementType)` Determine whether `ElementType` in the scope of `Method` requires non-null values.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### isNonNull

    public static boolean isNonNull(Method method,
                                    ElementType elementType)

Determine whether `ElementType` in the scope of `Method` requires non-null values. Non-nullability rules are discovered from class and package annotations. Non-null is applied when `Nonnull` is set to `When.ALWAYS`.

Parameters:
  `type` - the class to inspect.
  `elementType` - the element type.
Returns:
  true if `ElementType` allows null values by default.
See Also:
  `isNonNull(Annotation, ElementType)`

#### isNonNull

    public static boolean isNonNull(Class<?> type,
                                    ElementType elementType)

Determine whether `ElementType` in the scope of `type` requires non-null values. Non-nullability rules are discovered from class and package annotations. Non-null is applied when `Nonnull` is set to `When.ALWAYS`.

Parameters:
  `type` - the class to inspect.
  `elementType` - the element type.
Returns:
  true if `ElementType` allows null values by default.
See Also:
  `isNonNull(Annotation, ElementType)`

#### isNonNull

    public static boolean isNonNull(AnnotatedElement element,
                                    ElementType elementType)

Determine whether `ElementType` in the scope of `AnnotatedElement` requires non-null values. This method determines default `nullability` rules from the annotated element

Parameters:
  `element` - the scope of declaration, may be a `Package`, `Class`, or `Method`.
  `elementType` - the element type.
Returns:
  true if `ElementType` allows null values by default.

#### isExplicitNullable

    public static boolean isExplicitNullable(MethodParameter methodParameter)

Determine whether a `MethodParameter` is explicitly annotated to be considered nullable. Nullability rules are discovered from method and parameter annotations. A `MethodParameter` is considered nullable when `Nonnull` is set to one of `When.UNKNOWN`, `When.NEVER`, or `When.MAYBE`.

Parameters:
  `methodParameter` - the method parameter to inspect.
Returns:
  true if the parameter is nullable, false otherwise.