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

@@ -2,6 +2,8 @@
* Adapter classes for the Jetty WebSocket API.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.adapter.jetty;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Classes adapting Spring's WebSocket API to and from WebSocket providers.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.adapter;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Adapter classes for the standard Java WebSocket API.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.adapter.standard;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Client-side support for the Jetty WebSocket API.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.client.jetty;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Client-side abstractions for WebSocket applications.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.client;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Client-side classes for use with standard Java WebSocket endpoints.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.client.standard;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Support for annotation-based WebSocket setup in configuration classes.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.config.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Configuration support for WebSocket request handling.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.config;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* implementations and decorators.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.handler;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* WebSocket integration for Spring's messaging module.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.messaging;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Common abstractions and Spring configuration support for WebSocket applications.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Server-side abstractions for WebSocket interactions.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.server;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Server-side classes for use with standard JSR-356 WebSocket endpoints.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.server.standard;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* for upgrading a request.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.server.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* {@link org.springframework.web.socket.client.WebSocketClient}.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs.client;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* of SockJS message frames.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs.frame;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -2,6 +2,8 @@
* Top-level SockJS types.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -4,6 +4,8 @@
* implementation.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -4,6 +4,8 @@
* {@link org.springframework.web.socket.sockjs.SockJsService}.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs.transport.handler;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -7,6 +7,8 @@
* {@link org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService}.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs.transport;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -3,6 +3,8 @@
* {@link org.springframework.web.socket.WebSocketSession}.
*/
@NonNullApi
@NonNullFields
package org.springframework.web.socket.sockjs.transport.session;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;