Package org.springframework.data.util
Class NullableUtils
java.lang.Object
org.springframework.data.util.NullableUtils
Deprecated.
Utility methods to introspect nullability rules declared in packages, classes and methods.
Nullability rules are declared using Nullable, NonNullApi, and JSR-305
javax.annotation.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 themselves.
@org.jspecify.annotations.NullMarked 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) {
// …
}
}
javax.annotation.Nonnull is suitable for composition of meta-annotations and expresses via
javax.annotation.Nonnull#when() in which cases non-nullability is applicable.
- Since:
- 2.0
- Author:
- Mark Paluch
- See Also:
-
NonNullApiNullable
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisExplicitNullable(MethodParameter methodParameter) Deprecated.Determine whether aMethodParameteris explicitly annotated to be considered nullable.static booleanisNonNull(@Nullable AnnotatedElement element, ElementType elementType) Deprecated.Determine whetherElementTypein the scope ofAnnotatedElementrequires non-null values.static booleanisNonNull(Class<?> type, ElementType elementType) Deprecated.Determine whetherElementTypein the scope oftyperequires non-null values.static booleanisNonNull(Method method, ElementType elementType) Deprecated.Determine whetherElementTypein the scope ofMethodrequires non-null values.
-
Method Details
-
isNonNull
Deprecated.Determine whetherElementTypein the scope ofMethodrequires non-null values. Non-nullability rules are discovered from class and package annotations. Non-null is applied whenjavax.annotation.Nonnullis set tojavax.annotation.meta.When#ALWAYS.- Parameters:
method- the method to inspect.elementType- the element type.- Returns:
- false if
ElementTypeallows null values by default. true if the methods return type is aprimitiveand false if the method is void. - See Also:
-
isNonNull(Annotation, ElementType)
-
isNonNull
Deprecated.Determine whetherElementTypein the scope oftyperequires non-null values. Non-nullability rules are discovered from class and package annotations. Non-null is applied whenjavax.annotation.Nonnullis set tojavax.annotation.meta.When#ALWAYS.- Parameters:
type- the class to inspect.elementType- the element type.- Returns:
- false if
ElementTypeallows null values. true the given type is aprimitive. - See Also:
-
isNonNull(Annotation, ElementType)
-
isNonNull
@Contract("null, _ -> false") public static boolean isNonNull(@Nullable AnnotatedElement element, ElementType elementType) Deprecated.Determine whetherElementTypein the scope ofAnnotatedElementrequires non-null values. This method determines defaultjavax.annotation.Nonnull nullabilityrules from the annotated element- Parameters:
element- the scope of declaration, may be aPackage,Class, orMethod. Can be null.elementType- the element type.- Returns:
- false if
ElementTypeallows null values by default or if the givenAnnotatedElementis null.
-
isExplicitNullable
Deprecated.Determine whether aMethodParameteris explicitly annotated to be considered nullable. Nullability rules are discovered from method and parameter annotations. AMethodParameteris considered nullable whenjavax.annotation.Nonnullis set to one ofjavax.annotation.meta.When#UNKNOWN,javax.annotation.meta.When#NEVER, orjavax.annotation.meta.When#MAYBE.- Parameters:
methodParameter- the method parameter to inspect.- Returns:
- true if the parameter is nullable, false otherwise.
-
Nullnessfully using JSpecify annotations instead of Spring Framework's own @Nullable and @NonNullApi annotations.