|
|
|
@ -2,10 +2,9 @@ |
|
|
|
= Null-safety |
|
|
|
= Null-safety |
|
|
|
|
|
|
|
|
|
|
|
Although Java does not allow to express null-safety with its type system, Spring Framework |
|
|
|
Although Java does not allow to express null-safety with its type system, Spring Framework |
|
|
|
now provides annotations declared in the `org.springframework.lang` package to declare |
|
|
|
now provides annotations to declare nullability of APIs and fields. |
|
|
|
nullability of APIs and fields. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spring Framework leverages these annotations, but they can also be used in any Spring based |
|
|
|
Spring Framework leverages itself these annotations, but they can also be used in any Spring based |
|
|
|
Java project to declare null-safe APIs and optionally null-safe fields. Nullability of |
|
|
|
Java project to declare null-safe APIs and optionally null-safe fields. Nullability of |
|
|
|
types used inside method bodies is outside of the scope of this feature. |
|
|
|
types used inside method bodies is outside of the scope of this feature. |
|
|
|
|
|
|
|
|
|
|
|
@ -15,6 +14,11 @@ warnings to Java developers related to null-safety in order to avoid `NullPointe |
|
|
|
at runtime. JSR 305 meta-annotations allows tooling vendors to provide null-safety support |
|
|
|
at runtime. JSR 305 meta-annotations allows tooling vendors to provide null-safety support |
|
|
|
in a generic way, without having to hard-code support for Spring annotations. |
|
|
|
in a generic way, without having to hard-code support for Spring annotations. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NOTE] |
|
|
|
|
|
|
|
==== |
|
|
|
|
|
|
|
It is not necessary nor recommanded to have JSR 305 dependency in user project classpath. |
|
|
|
|
|
|
|
==== |
|
|
|
|
|
|
|
|
|
|
|
They are also used by Kotlin which supports natively |
|
|
|
They are also used by Kotlin which supports natively |
|
|
|
https://kotlinlang.org/docs/reference/null-safety.html[null-safety]. By default, types from |
|
|
|
https://kotlinlang.org/docs/reference/null-safety.html[null-safety]. By default, types from |
|
|
|
Java APIs used in Kotlin are recognized as |
|
|
|
Java APIs used in Kotlin are recognized as |
|
|
|
@ -31,7 +35,7 @@ Other libraries like Reactor or Spring Data leverage these annotations as well t |
|
|
|
null-safe APIs. |
|
|
|
null-safe APIs. |
|
|
|
==== |
|
|
|
==== |
|
|
|
|
|
|
|
|
|
|
|
The following annotations are provided: |
|
|
|
The following annotations are provided in the `org.springframework.lang` package: |
|
|
|
|
|
|
|
|
|
|
|
* {api-spring-framework}/lang/NonNull.html[`@NonNull`] annotation where specific parameter, |
|
|
|
* {api-spring-framework}/lang/NonNull.html[`@NonNull`] annotation where specific parameter, |
|
|
|
return value, generic type argument, varargs element, array element or field cannot be `null` |
|
|
|
return value, generic type argument, varargs element, array element or field cannot be `null` |
|
|
|
|