Top Description Constructors Methods
org.hibernate.internal.util

public final Class NullnessUtil

extends Object
Class Inheritance
Annotations
@SuppressWarnings:nullness, cast
@AnnotatedFor:nullness
Imports
org.checkerframework.checker.nullness.qual.EnsuresNonNull, .NonNull, .Nullable, org.checkerframework.framework.qual.AnnotatedFor

Utility class for the Nullness Checker.

To avoid the need to write the NullnessUtil class name, do:

import static org.checkerframework.checker.nullness.util.NullnessUtil.castNonNull;

or

import static org.checkerframework.checker.nullness.util.NullnessUtil.*;

Runtime Dependency: If you use this class, you must distribute (or link to) checker-qual.jar, along with your binaries. Or, you can copy this class into your own project.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
the type of the reference
T extends @Nullable Object
>
@NonNull T

Returns:

the argument, casted to have the type qualifier @NonNull
castNonNull
(@Nullable T
a reference of @Nullable type, that is non-null at run time
ref
)

A method that suppresses warnings from the Nullness Checker.

public static <
the type of the reference
T extends @Nullable Object
>
@NonNull T

Returns:

the argument, casted to have the type qualifier @NonNull
castNonNull
(@Nullable T
a reference of @Nullable type, that is non-null at run time
ref
,
String
text to include if this method is misused
message
)

Suppress warnings from the Nullness Checker, with a custom error message.

private static <
the component type (five levels in) of the array
T extends @Nullable Object
>
@NonNull @NonNull T[]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullArray
(@Nullable T[]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
,
@Nullable String
text to include if there is a non-null value, or null to use uncustomized message
message
)

The implementation of castNonNullDeep.

public static <
the component type of the array
T extends @Nullable Object
>
@NonNull @NonNull T[]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable T[]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type of the array
T extends @Nullable Object
>
@NonNull @NonNull T[]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable T[]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
,
String
text to include if this method is misused
message
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type of the component type of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable T[][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type of the component type of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable T[][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
,
String
text to include if this method is misused
message
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type (three levels in) of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable @Nullable T[][][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type (three levels in) of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable @Nullable T[][][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
,
String
text to include if this method is misused
message
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][][][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable @Nullable @Nullable T[][][][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type (four levels in) of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][][][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable @Nullable @Nullable T[][][][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
,
String
text to include if this method is misused
message
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type (four levels in) of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][][][][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable @Nullable @Nullable @Nullable T[][][][][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

public static <
the component type (five levels in) of the array
T extends @Nullable Object
>
@NonNull @NonNull T[][][][][]

Returns:

the argument, casted to have the type qualifier @NonNull at all levels
castNonNullDeep
(@Nullable @Nullable @Nullable @Nullable @Nullable T[][][][][]
an array all of whose elements, and their elements recursively, are non-null at run time
arr
,
String
text to include if this method is misused
message
)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array.

private static void
checkIfArray(@NonNull Object
a value; if an array, all of its elements, and their elements recursively, are non-null at run time
ref
,
@Nullable String
text to include if there is a non-null value, or null to use uncustomized message
message
)

If the argument is an array, requires it to be non-null at all levels.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NullnessUtilback to summary
private NullnessUtil()

Method Detail

castNonNullback to summary
public static <T extends @Nullable Object> @NonNull T castNonNull(@Nullable T ref)

A method that suppresses warnings from the Nullness Checker.

The method takes a possibly-null reference, unsafely casts it to have the @NonNull type qualifier, and returns it. The Nullness Checker considers both the return value, and also the argument, to be non-null after the method call. Therefore, the castNonNull method can be used either as a cast expression or as a statement. The Nullness Checker issues no warnings in any of the following code:


  // one way to use as a cast:
 @NonNull String s = castNonNull(possiblyNull1);

  // another way to use as a cast:
  castNonNull(possiblyNull2).toString();

  // one way to use as a statement:
  castNonNull(possiblyNull3);
  possiblyNull3.toString();`

The castNonNull method is intended to be used in situations where the programmer definitively knows that a given reference is not null, but the type system is unable to make this deduction. It is not intended for defensive programming, in which a programmer cannot prove that the value is not null but wishes to have an earlier indication if it is. See the Checker Framework Manual for further discussion.

The method throws AssertionError if Java assertions are enabled and the argument is null. If the exception is ever thrown, then that indicates that the programmer misused the method by using it in a circumstance where its argument can be null.

Parameters
<T>
the type of the reference
ref:@Nullable T

a reference of @Nullable type, that is non-null at run time

Returns:@NonNull T

the argument, casted to have the type qualifier @NonNull

Annotations
@EnsuresNonNull:#1
castNonNullback to summary
public static <T extends @Nullable Object> @NonNull T castNonNull(@Nullable T ref, String message)

Suppress warnings from the Nullness Checker, with a custom error message. See castNonNull(Object) for documentation.

Parameters
<T>
the type of the reference
ref:@Nullable T

a reference of @Nullable type, that is non-null at run time

message:String

text to include if this method is misused

Returns:@NonNull T

the argument, casted to have the type qualifier @NonNull

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullArrayback to summary
private static <T extends @Nullable Object> @NonNull @NonNull T[] castNonNullArray(@Nullable T[] arr, @Nullable String message)

The implementation of castNonNullDeep.

Parameters
<T>
the component type (five levels in) of the array
arr:@Nullable T[]

an array all of whose elements, and their elements recursively, are non-null at run time

message:@Nullable String

text to include if there is a non-null value, or null to use uncustomized message

Returns:@NonNull @NonNull T[]

the argument, casted to have the type qualifier @NonNull at all levels

castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[] castNonNullDeep(@Nullable T[] arr)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type of the array
arr:@Nullable T[]

an array all of whose elements, and their elements recursively, are non-null at run time

Returns:@NonNull @NonNull T[]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[] castNonNullDeep(@Nullable T[] arr, String message)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type of the array
arr:@Nullable T[]

an array all of whose elements, and their elements recursively, are non-null at run time

message:String

text to include if this method is misused

Returns:@NonNull @NonNull T[]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][] castNonNullDeep(@Nullable @Nullable T[][] arr)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type of the component type of the array
arr:@Nullable @Nullable T[][]

an array all of whose elements, and their elements recursively, are non-null at run time

Returns:@NonNull @NonNull T[][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][] castNonNullDeep(@Nullable @Nullable T[][] arr, String message)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type of the component type of the array
arr:@Nullable @Nullable T[][]

an array all of whose elements, and their elements recursively, are non-null at run time

message:String

text to include if this method is misused

Returns:@NonNull @NonNull T[][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][][] castNonNullDeep(@Nullable @Nullable @Nullable T[][][] arr)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type (three levels in) of the array
arr:@Nullable @Nullable @Nullable T[][][]

an array all of whose elements, and their elements recursively, are non-null at run time

Returns:@NonNull @NonNull T[][][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][][] castNonNullDeep(@Nullable @Nullable @Nullable T[][][] arr, String message)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type (three levels in) of the array
arr:@Nullable @Nullable @Nullable T[][][]

an array all of whose elements, and their elements recursively, are non-null at run time

message:String

text to include if this method is misused

Returns:@NonNull @NonNull T[][][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][][][] castNonNullDeep(@Nullable @Nullable @Nullable @Nullable T[][][][] arr)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type of the array
arr:@Nullable @Nullable @Nullable @Nullable T[][][][]

an array all of whose elements, and their elements recursively, are non-null at run time

Returns:@NonNull @NonNull T[][][][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][][][] castNonNullDeep(@Nullable @Nullable @Nullable @Nullable T[][][][] arr, String message)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type (four levels in) of the array
arr:@Nullable @Nullable @Nullable @Nullable T[][][][]

an array all of whose elements, and their elements recursively, are non-null at run time

message:String

text to include if this method is misused

Returns:@NonNull @NonNull T[][][][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][][][][] castNonNullDeep(@Nullable @Nullable @Nullable @Nullable @Nullable T[][][][][] arr)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type (four levels in) of the array
arr:@Nullable @Nullable @Nullable @Nullable @Nullable T[][][][][]

an array all of whose elements, and their elements recursively, are non-null at run time

Returns:@NonNull @NonNull T[][][][][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
castNonNullDeepback to summary
public static <T extends @Nullable Object> @NonNull @NonNull T[][][][][] castNonNullDeep(@Nullable @Nullable @Nullable @Nullable @Nullable T[][][][][] arr, String message)

Like castNonNull, but whereas that method only checks and casts the reference itself, this traverses all levels of the argument array. The array is recursively checked to ensure that all elements at every array level are non-null.

Parameters
<T>
the component type (five levels in) of the array
arr:@Nullable @Nullable @Nullable @Nullable @Nullable T[][][][][]

an array all of whose elements, and their elements recursively, are non-null at run time

message:String

text to include if this method is misused

Returns:@NonNull @NonNull T[][][][][]

the argument, casted to have the type qualifier @NonNull at all levels

Annotations
@EnsuresNonNull:#1
See Also
castNonNull(Object)
checkIfArrayback to summary
private static void checkIfArray(@NonNull Object ref, @Nullable String message)

If the argument is an array, requires it to be non-null at all levels.

Parameters
ref:@NonNull Object

a value; if an array, all of its elements, and their elements recursively, are non-null at run time

message:@Nullable String

text to include if there is a non-null value, or null to use uncustomized message