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:
@@ -8,6 +8,8 @@
|
||||
* unit tests for code that depends on environment-specific properties.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.env;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* {@code MockClientHttpResponse}.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.http.client;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Mock implementations of reactive HTTP client contracts.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.http.client.reactive;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* {@code MockHttpOutputMessage}.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.http;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Mock implementations of reactive HTTP server contracts.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.http.server.reactive;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* configuration can be reused without changes.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.jndi;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* (<a href="http://www.mockobjects.com">MockObjects</a>).
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.web;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.web.reactive.function.server;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Support classes for annotation-driven tests.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.annotation;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Support for context caching within the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.cache;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* including support for declarative SQL script execution via {@code @Sql}.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.jdbc;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* with the JUnit Jupiter extension model in JUnit 5.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.junit.jupiter;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* with the JUnit Jupiter extension model in JUnit 5.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.junit.jupiter.web;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* with JUnit 4.12 or higher.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.junit4;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Custom JUnit {@code Rules} used in the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.junit4.rules;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Custom JUnit {@code Statements} used in the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.junit4.statements;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
* management with default rollback semantics.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Support classes for the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.support;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* tests run with TestNG and the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.testng;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Transactional support classes for the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.transaction;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Common utilities used within the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.util;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Web support classes for the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.web;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* WebSocket support classes for the <em>Spring TestContext Framework</em>.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.context.web.socket;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* Support classes for tests based on JDBC.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.jdbc;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* General utility classes for use in unit and integration tests.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.util;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* to gain access to instances of those implementations.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.client.match;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* @see org.springframework.test.web.client.MockRestServiceServer
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.client;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* to gain access to instances of those implementations.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.client.response;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* {@link org.springframework.test.web.reactive.server.WebTestClient}.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.reactive.server;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* @see org.springframework.test.web.servlet.MockMvc
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* @see org.openqa.selenium.htmlunit.HtmlUnitDriver
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.servlet.htmlunit.webdriver;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* @see org.springframework.test.web.servlet.MockMvc
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.servlet;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* to gain access to instances of those implementations.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.servlet.request;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* to access instances of those implementations.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.servlet.result;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* to access to instances of those implementations.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.test.web.servlet.setup;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
|
||||
Reference in New Issue
Block a user