Revisit nullability annotations

This commit introduces the following changes.

1) It adds a new Spring @NonNull annotation which allows to apply
@NonNullApi semantic on a specific element, like @Nullable does.
Combined with @Nullable, it allows partial null-safety support when
package granularity is too broad.

2) @Nullable and @NonNull can apply to ElementType.TYPE_USE in order
to be used on generic type arguments (SPR-15942).

3) Annotations does not apply to ElementType.TYPE_PARAMETER anymore
since it is not supported yet (applicability for such use case is
controversial and need to be discussed).

4) @NonNullApi does not apply to ElementType.FIELD anymore since in a
lot of use cases (private, protected) it is not part for the public API
+ its usage should remain opt-in. A dedicated @NonNullFields annotation
has been added in order to set fields default to non-nullable.

5) Updated Javadoc and reference documentation.

Issue: SPR-15756
This commit is contained in:
Sebastien Deleuze
2017-09-15 13:26:41 +02:00
parent ec2218c967
commit 1bc93e3d0f
364 changed files with 1003 additions and 113 deletions

View File

@@ -3,6 +3,8 @@
* within Spring's O/X Mapping support.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.castor;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Provides an namespace handler for the Spring Object/XML namespace.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.config;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* with Spring's O/X Mapping support.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.jaxb;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* with Spring's O/X Mapping support.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.jibx;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Contains (un)marshallers optimized to store binary data in MIME attachments.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.mime;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -4,6 +4,8 @@
* and XmlMappingExceptions related to O/X Mapping
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -5,6 +5,8 @@
* MarshallingMessageConverter for use within Spring's JMS support.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* with Spring's O/X Mapping support.
*/
@NonNullApi
@NonNullFields
package org.springframework.oxm.xstream;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;