Switch to JSpecify annotations

This commit updates the whole Spring Framework codebase to use JSpecify
annotations instead of Spring null-safety annotations with JSR 305
semantics.

JSpecify provides signficant enhancements such as properly defined
specifications, a canonical dependency with no split-package issue,
better tooling, better Kotlin integration and the capability to specify
generic type, array and varargs element null-safety. Generic type
null-safety is not defined by this commit yet and will be specified
later.

A key difference is that Spring null-safety annotations, following
JSR 305 semantics, apply to fields, parameters and return values,
while JSpecify annotations apply to type usages. That's why this
commit moves nullability annotations closer to the type for fields
and return values.

See gh-28797
This commit is contained in:
Sébastien Deleuze
2024-12-03 15:22:37 +01:00
parent fcb8aed03f
commit bc5d771a06
3459 changed files with 14118 additions and 22059 deletions

View File

@@ -7,9 +7,7 @@
* <p>These <em>mocks</em> are useful for developing <em>out-of-container</em>
* unit tests for code that depends on environment-specific properties.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.env;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -21,10 +21,11 @@ import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.mock.http.MockHttpOutputMessage;
import org.springframework.util.Assert;
import org.springframework.web.util.UriComponentsBuilder;
@@ -43,13 +44,11 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
private URI uri;
@Nullable
private ClientHttpResponse clientHttpResponse;
private @Nullable ClientHttpResponse clientHttpResponse;
private boolean executed = false;
@Nullable
Map<String, Object> attributes;
@Nullable Map<String, Object> attributes;
/**

View File

@@ -3,9 +3,7 @@
* This package contains {@code MockClientHttpRequest} and
* {@code MockClientHttpResponse}.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.http.client;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Mock implementations of reactive HTTP client contracts.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.http.client.reactive;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -3,9 +3,7 @@
* This package contains {@code MockHttpInputMessage} and
* {@code MockHttpOutputMessage}.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.http;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
@@ -38,7 +39,6 @@ import org.springframework.http.HttpRange;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.AbstractServerHttpRequest;
import org.springframework.http.server.reactive.SslInfo;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MimeType;
@@ -56,14 +56,11 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private final MultiValueMap<String, HttpCookie> cookies;
@Nullable
private final InetSocketAddress localAddress;
private final @Nullable InetSocketAddress localAddress;
@Nullable
private final InetSocketAddress remoteAddress;
private final @Nullable InetSocketAddress remoteAddress;
@Nullable
private final SslInfo sslInfo;
private final @Nullable SslInfo sslInfo;
private final Flux<DataBuffer> body;
@@ -82,20 +79,17 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
@Override
@Nullable
public InetSocketAddress getLocalAddress() {
public @Nullable InetSocketAddress getLocalAddress() {
return this.localAddress;
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
public @Nullable InetSocketAddress getRemoteAddress() {
return this.remoteAddress;
}
@Override
@Nullable
protected SslInfo initSslInfo() {
protected @Nullable SslInfo initSslInfo() {
return this.sslInfo;
}
@@ -415,8 +409,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private final URI url;
@Nullable
private String contextPath;
private @Nullable String contextPath;
private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance();
@@ -424,14 +417,11 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
@Nullable
private InetSocketAddress remoteAddress;
private @Nullable InetSocketAddress remoteAddress;
@Nullable
private InetSocketAddress localAddress;
private @Nullable InetSocketAddress localAddress;
@Nullable
private SslInfo sslInfo;
private @Nullable SslInfo sslInfo;
DefaultBodyBuilder(HttpMethod method, URI url) {
this.method = method;

View File

@@ -1,9 +1,7 @@
/**
* Mock implementations of reactive HTTP server contracts.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.http.server.reactive;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -21,7 +21,8 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.CollectionUtils;
/**
@@ -63,13 +64,11 @@ class HeaderValueHolder {
return this.values.stream().map(Object::toString).toList();
}
@Nullable
Object getValue() {
@Nullable Object getValue() {
return (!this.values.isEmpty() ? this.values.get(0) : null);
}
@Nullable
String getStringValue() {
@Nullable String getStringValue() {
return (!this.values.isEmpty() ? String.valueOf(this.values.get(0)) : null);
}

View File

@@ -29,9 +29,9 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.util.WebUtils;
@@ -45,13 +45,11 @@ public class MockAsyncContext implements AsyncContext {
private final HttpServletRequest request;
@Nullable
private final HttpServletResponse response;
private final @Nullable HttpServletResponse response;
private final List<AsyncListener> listeners = new ArrayList<>();
@Nullable
private String dispatchedPath;
private @Nullable String dispatchedPath;
private long timeout = 10 * 1000L;
@@ -82,8 +80,7 @@ public class MockAsyncContext implements AsyncContext {
}
@Override
@Nullable
public ServletResponse getResponse() {
public @Nullable ServletResponse getResponse() {
return this.response;
}
@@ -110,8 +107,7 @@ public class MockAsyncContext implements AsyncContext {
}
}
@Nullable
public String getDispatchedPath() {
public @Nullable String getDispatchedPath() {
return this.dispatchedPath;
}

View File

@@ -24,8 +24,7 @@ import java.io.Writer;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.tagext.BodyContent;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Mock implementation of the {@link jakarta.servlet.jsp.tagext.BodyContent} class.

View File

@@ -21,9 +21,9 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import jakarta.servlet.http.Cookie;
import org.jspecify.annotations.Nullable;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -54,8 +54,7 @@ public class MockCookie extends Cookie {
private static final String EXPIRES = "Expires";
@Nullable
private ZonedDateTime expires;
private @Nullable ZonedDateTime expires;
/**
@@ -81,8 +80,7 @@ public class MockCookie extends Cookie {
* @return the "Expires" attribute for this cookie, or {@code null} if not set
* @since 5.1.11
*/
@Nullable
public ZonedDateTime getExpires() {
public @Nullable ZonedDateTime getExpires() {
return this.expires;
}
@@ -101,8 +99,7 @@ public class MockCookie extends Cookie {
* Get the "SameSite" attribute for this cookie.
* @return the "SameSite" attribute for this cookie, or {@code null} if not set
*/
@Nullable
public String getSameSite() {
public @Nullable String getSameSite() {
return getAttribute(SAME_SITE);
}

View File

@@ -28,8 +28,8 @@ import jakarta.servlet.Servlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -50,16 +50,13 @@ import org.springframework.util.ObjectUtils;
*/
public class MockFilterChain implements FilterChain {
@Nullable
private ServletRequest request;
private @Nullable ServletRequest request;
@Nullable
private ServletResponse response;
private @Nullable ServletResponse response;
private final List<Filter> filters;
@Nullable
private Iterator<Filter> iterator;
private @Nullable Iterator<Filter> iterator;
/**
@@ -100,16 +97,14 @@ public class MockFilterChain implements FilterChain {
/**
* Return the request that {@link #doFilter} has been called with.
*/
@Nullable
public ServletRequest getRequest() {
public @Nullable ServletRequest getRequest() {
return this.request;
}
/**
* Return the response that {@link #doFilter} has been called with.
*/
@Nullable
public ServletResponse getResponse() {
public @Nullable ServletResponse getResponse() {
return this.response;
}

View File

@@ -23,8 +23,8 @@ import java.util.Map;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletContext;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -97,8 +97,7 @@ public class MockFilterConfig implements FilterConfig {
}
@Override
@Nullable
public String getInitParameter(String name) {
public @Nullable String getInitParameter(String name) {
Assert.notNull(name, "Parameter name must not be null");
return this.initParameters.get(name);
}

View File

@@ -29,8 +29,7 @@ import java.util.Set;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Mock implementation of {@link FilterRegistration}.
@@ -68,9 +67,8 @@ public class MockFilterRegistration implements FilterRegistration.Dynamic {
return this.name;
}
@Nullable
@Override
public String getClassName() {
public @Nullable String getClassName() {
return this.className;
}
@@ -79,9 +77,8 @@ public class MockFilterRegistration implements FilterRegistration.Dynamic {
return (this.initParameters.putIfAbsent(name, value) != null);
}
@Nullable
@Override
public String getInitParameter(String name) {
public @Nullable String getInitParameter(String name) {
return this.initParameters.get(name);
}

View File

@@ -18,8 +18,7 @@ package org.springframework.mock.web;
import jakarta.servlet.http.HttpServletMapping;
import jakarta.servlet.http.MappingMatch;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Mock implementation of {@link HttpServletMapping}.
@@ -39,8 +38,7 @@ public class MockHttpServletMapping implements HttpServletMapping {
private final String servletName;
@Nullable
private final MappingMatch mappingMatch;
private final @Nullable MappingMatch mappingMatch;
public MockHttpServletMapping(
@@ -69,8 +67,7 @@ public class MockHttpServletMapping implements HttpServletMapping {
}
@Override
@Nullable
public MappingMatch getMappingMatch() {
public @Nullable MappingMatch getMappingMatch() {
return this.mappingMatch;
}

View File

@@ -62,10 +62,10 @@ import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpUpgradeHandler;
import jakarta.servlet.http.MappingMatch;
import jakarta.servlet.http.Part;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.LinkedMultiValueMap;
@@ -170,20 +170,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
private final Map<String, Object> attributes = new LinkedHashMap<>();
@Nullable
private String characterEncoding;
private @Nullable String characterEncoding;
@Nullable
private byte[] content;
private byte @Nullable [] content;
@Nullable
private String contentType;
private @Nullable String contentType;
@Nullable
private ServletInputStream inputStream;
private @Nullable ServletInputStream inputStream;
@Nullable
private BufferedReader reader;
private @Nullable BufferedReader reader;
private final Map<String, String[]> parameters = new LinkedHashMap<>(16);
@@ -216,8 +211,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private boolean asyncSupported = false;
@Nullable
private MockAsyncContext asyncContext;
private @Nullable MockAsyncContext asyncContext;
private DispatcherType dispatcherType = DispatcherType.REQUEST;
@@ -226,46 +220,35 @@ public class MockHttpServletRequest implements HttpServletRequest {
// HttpServletRequest properties
// ---------------------------------------------------------------------
@Nullable
private String authType;
private @Nullable String authType;
@Nullable
private Cookie[] cookies;
private Cookie @Nullable [] cookies;
private final Map<String, HeaderValueHolder> headers = new LinkedCaseInsensitiveMap<>();
@Nullable
private String method;
private @Nullable String method;
@Nullable
private String pathInfo;
private @Nullable String pathInfo;
private String contextPath = "";
@Nullable
private String queryString;
private @Nullable String queryString;
@Nullable
private String remoteUser;
private @Nullable String remoteUser;
private final Set<String> userRoles = new HashSet<>();
@Nullable
private Principal userPrincipal;
private @Nullable Principal userPrincipal;
@Nullable
private String requestedSessionId;
private @Nullable String requestedSessionId;
@Nullable
private String uriTemplate;
private @Nullable String uriTemplate;
@Nullable
private String requestURI;
private @Nullable String requestURI;
private String servletPath = "";
@Nullable
private HttpSession session;
private @Nullable HttpSession session;
private boolean requestedSessionIdValid = true;
@@ -275,8 +258,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private final MultiValueMap<String, Part> parts = new LinkedMultiValueMap<>();
@Nullable
private HttpServletMapping httpServletMapping;
private @Nullable HttpServletMapping httpServletMapping;
// ---------------------------------------------------------------------
@@ -385,8 +367,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
// ---------------------------------------------------------------------
@Override
@Nullable
public Object getAttribute(String name) {
public @Nullable Object getAttribute(String name) {
checkActive();
return this.attributes.get(name);
}
@@ -398,8 +379,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getCharacterEncoding() {
public @Nullable String getCharacterEncoding() {
return this.characterEncoding;
}
@@ -429,7 +409,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* @see #getContentAsByteArray()
* @see #getContentAsString()
*/
public void setContent(@Nullable byte[] content) {
public void setContent(byte @Nullable [] content) {
this.content = content;
this.inputStream = null;
this.reader = null;
@@ -442,8 +422,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* @see #setContent(byte[])
* @see #getContentAsString()
*/
@Nullable
public byte[] getContentAsByteArray() {
public byte @Nullable [] getContentAsByteArray() {
return this.content;
}
@@ -458,8 +437,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* @see #setCharacterEncoding(String)
* @see #getContentAsByteArray()
*/
@Nullable
public String getContentAsString() throws IllegalStateException, UnsupportedEncodingException {
public @Nullable String getContentAsString() throws IllegalStateException, UnsupportedEncodingException {
Assert.state(this.characterEncoding != null,
"Cannot get content as a String for a null character encoding. " +
"Consider setting the characterEncoding in the request.");
@@ -502,8 +480,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getContentType() {
public @Nullable String getContentType() {
return this.contentType;
}
@@ -628,8 +605,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getParameter(String name) {
public @Nullable String getParameter(String name) {
Assert.notNull(name, "Parameter name must not be null");
String[] arr = this.parameters.get(name);
return (arr != null && arr.length > 0 ? arr[0] : null);
@@ -641,8 +617,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String[] getParameterValues(String name) {
public String @Nullable [] getParameterValues(String name) {
Assert.notNull(name, "Parameter name must not be null");
return this.parameters.get(name);
}
@@ -965,8 +940,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public AsyncContext getAsyncContext() {
public @Nullable AsyncContext getAsyncContext() {
return this.asyncContext;
}
@@ -1021,12 +995,11 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getAuthType() {
public @Nullable String getAuthType() {
return this.authType;
}
public void setCookies(@Nullable Cookie... cookies) {
public void setCookies(Cookie @Nullable ... cookies) {
this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies);
if (this.cookies == null) {
removeHeader(HttpHeaders.COOKIE);
@@ -1043,8 +1016,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public Cookie[] getCookies() {
public Cookie @Nullable [] getCookies() {
return this.cookies;
}
@@ -1166,8 +1138,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getHeader(String name) {
public @Nullable String getHeader(String name) {
HeaderValueHolder header = this.headers.get(name);
return (header != null ? header.getStringValue() : null);
}
@@ -1207,8 +1178,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getMethod() {
public @Nullable String getMethod() {
return this.method;
}
@@ -1217,14 +1187,12 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getPathInfo() {
public @Nullable String getPathInfo() {
return this.pathInfo;
}
@Override
@Nullable
public String getPathTranslated() {
public @Nullable String getPathTranslated() {
return (this.pathInfo != null ? this.servletContext.getRealPath(this.pathInfo) : null);
}
@@ -1242,8 +1210,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getQueryString() {
public @Nullable String getQueryString() {
return this.queryString;
}
@@ -1252,8 +1219,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getRemoteUser() {
public @Nullable String getRemoteUser() {
return this.remoteUser;
}
@@ -1273,8 +1239,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public Principal getUserPrincipal() {
public @Nullable Principal getUserPrincipal() {
return this.userPrincipal;
}
@@ -1283,8 +1248,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getRequestedSessionId() {
public @Nullable String getRequestedSessionId() {
return this.requestedSessionId;
}
@@ -1301,8 +1265,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* Return the original URI template used to prepare the request, if any.
* @since 6.2
*/
@Nullable
public String getUriTemplate() {
public @Nullable String getUriTemplate() {
return this.uriTemplate;
}
@@ -1311,8 +1274,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public String getRequestURI() {
public @Nullable String getRequestURI() {
return this.requestURI;
}
@@ -1351,8 +1313,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public HttpSession getSession(boolean create) {
public @Nullable HttpSession getSession(boolean create) {
checkActive();
// Reset session if invalidated.
if (this.session instanceof MockHttpSession mockSession && mockSession.isInvalid()) {
@@ -1366,8 +1327,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public HttpSession getSession() {
public @Nullable HttpSession getSession() {
return getSession(true);
}
@@ -1435,8 +1395,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
@Override
@Nullable
public Part getPart(String name) throws IOException, ServletException {
public @Nullable Part getPart(String name) throws IOException, ServletException {
return this.parts.getFirst(name);
}
@@ -1466,8 +1425,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* This helps {@link org.springframework.web.util.ServletRequestPathUtils}
* to take into account the Servlet path when parsing the requestURI.
*/
@Nullable
private MappingMatch determineMappingMatch() {
private @Nullable MappingMatch determineMappingMatch() {
if (StringUtils.hasText(this.requestURI) && StringUtils.hasText(this.servletPath)) {
String path = UrlPathHelper.defaultInstance.getRequestUri(this);
String prefix = this.contextPath + this.servletPath;

View File

@@ -43,10 +43,10 @@ import java.util.TimeZone;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.StringUtils;
@@ -99,13 +99,11 @@ public class MockHttpServletResponse implements HttpServletResponse {
private final ServletOutputStream outputStream = new ResponseServletOutputStream(this.content);
@Nullable
private PrintWriter writer;
private @Nullable PrintWriter writer;
private long contentLength = 0;
@Nullable
private String contentType;
private @Nullable String contentType;
private int bufferSize = 4096;
@@ -124,16 +122,14 @@ public class MockHttpServletResponse implements HttpServletResponse {
private int status = HttpServletResponse.SC_OK;
@Nullable
private String errorMessage;
private @Nullable String errorMessage;
//---------------------------------------------------------------------
// Properties for MockRequestDispatcher
//---------------------------------------------------------------------
@Nullable
private String forwardedUrl;
private @Nullable String forwardedUrl;
private final List<String> includedUrls = new ArrayList<>();
@@ -372,8 +368,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
@Override
@Nullable
public String getContentType() {
public @Nullable String getContentType() {
return this.contentType;
}
@@ -510,8 +505,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
return this.cookies.toArray(new Cookie[0]);
}
@Nullable
public Cookie getCookie(String name) {
public @Nullable Cookie getCookie(String name) {
Assert.notNull(name, "Cookie name must not be null");
for (Cookie cookie : this.cookies) {
if (name.equals(cookie.getName())) {
@@ -546,8 +540,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
* @see HttpServletResponse#getHeader(String)
*/
@Override
@Nullable
public String getHeader(String name) {
public @Nullable String getHeader(String name) {
HeaderValueHolder header = this.headers.get(name);
return (header != null ? header.getStringValue() : null);
}
@@ -577,8 +570,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
* @param name the name of the header
* @return the associated header value, or {@code null} if none
*/
@Nullable
public Object getHeaderValue(String name) {
public @Nullable Object getHeaderValue(String name) {
HeaderValueHolder header = this.headers.get(name);
return (header != null ? header.getValue() : null);
}
@@ -649,8 +641,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
setCommitted(true);
}
@Nullable
public String getRedirectedUrl() {
public @Nullable String getRedirectedUrl() {
return getHeader(HttpHeaders.LOCATION);
}
@@ -807,8 +798,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
/**
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
*/
@Nullable
public String getErrorMessage() {
public @Nullable String getErrorMessage() {
return this.errorMessage;
}
@@ -821,8 +811,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
this.forwardedUrl = forwardedUrl;
}
@Nullable
public String getForwardedUrl() {
public @Nullable String getForwardedUrl() {
return this.forwardedUrl;
}
@@ -833,8 +822,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
}
@Nullable
public String getIncludedUrl() {
public @Nullable String getIncludedUrl() {
int count = this.includedUrls.size();
Assert.state(count <= 1,
() -> "More than 1 URL included - check getIncludedUrls instead: " + this.includedUrls);

View File

@@ -29,8 +29,8 @@ import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSessionBindingEvent;
import jakarta.servlet.http.HttpSessionBindingListener;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -147,8 +147,7 @@ public class MockHttpSession implements HttpSession {
}
@Override
@Nullable
public Object getAttribute(String name) {
public @Nullable Object getAttribute(String name) {
assertIsValid();
Assert.notNull(name, "Attribute name must not be null");
return this.attributes.get(name);

View File

@@ -22,8 +22,7 @@ import java.io.Writer;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.jsp.JspWriter;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Mock implementation of the {@link jakarta.servlet.jsp.JspWriter} class.
@@ -36,8 +35,7 @@ public class MockJspWriter extends JspWriter {
private final HttpServletResponse response;
@Nullable
private PrintWriter targetWriter;
private @Nullable PrintWriter targetWriter;
/**

View File

@@ -21,8 +21,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -45,8 +46,7 @@ public class MockMultipartFile implements MultipartFile {
private final String originalFilename;
@Nullable
private final String contentType;
private final @Nullable String contentType;
private final byte[] content;
@@ -56,7 +56,7 @@ public class MockMultipartFile implements MultipartFile {
* @param name the name of the file
* @param content the content of the file
*/
public MockMultipartFile(String name, @Nullable byte[] content) {
public MockMultipartFile(String name, byte @Nullable [] content) {
this(name, "", null, content);
}
@@ -78,7 +78,7 @@ public class MockMultipartFile implements MultipartFile {
* @param content the content of the file
*/
public MockMultipartFile(
String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) {
String name, @Nullable String originalFilename, @Nullable String contentType, byte @Nullable [] content) {
Assert.hasLength(name, "Name must not be empty");
this.name = name;
@@ -109,14 +109,12 @@ public class MockMultipartFile implements MultipartFile {
}
@Override
@NonNull
public String getOriginalFilename() {
public @NonNull String getOriginalFilename() {
return this.originalFilename;
}
@Override
@Nullable
public String getContentType() {
public @Nullable String getContentType() {
return this.contentType;
}

View File

@@ -28,10 +28,10 @@ import java.util.Objects;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Part;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -96,8 +96,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
}
@Override
@Nullable
public MultipartFile getFile(String name) {
public @Nullable MultipartFile getFile(String name) {
return this.multipartFiles.getFirst(name);
}
@@ -118,8 +117,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
}
@Override
@Nullable
public String getMultipartContentType(String paramOrFileName) {
public @Nullable String getMultipartContentType(String paramOrFileName) {
MultipartFile file = getFile(paramOrFileName);
if (file != null) {
return file.getContentType();
@@ -156,8 +154,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
}
@Override
@Nullable
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
public @Nullable HttpHeaders getMultipartHeaders(String paramOrFileName) {
MultipartFile file = getFile(paramOrFileName);
if (file != null) {
HttpHeaders headers = new HttpHeaders();

View File

@@ -36,8 +36,8 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -63,8 +63,7 @@ public class MockPageContext extends PageContext {
private final Map<String, Object> attributes = new LinkedHashMap<>();
@Nullable
private JspWriter out;
private @Nullable JspWriter out;
/**
@@ -163,15 +162,13 @@ public class MockPageContext extends PageContext {
}
@Override
@Nullable
public Object getAttribute(String name) {
public @Nullable Object getAttribute(String name) {
Assert.notNull(name, "Attribute name must not be null");
return this.attributes.get(name);
}
@Override
@Nullable
public Object getAttribute(String name, int scope) {
public @Nullable Object getAttribute(String name, int scope) {
Assert.notNull(name, "Attribute name must not be null");
return switch (scope) {
case PAGE_SCOPE -> getAttribute(name);
@@ -186,8 +183,7 @@ public class MockPageContext extends PageContext {
}
@Override
@Nullable
public Object findAttribute(String name) {
public @Nullable Object findAttribute(String name) {
Object value = getAttribute(name);
if (value == null) {
value = getAttribute(name, REQUEST_SCOPE);
@@ -268,8 +264,7 @@ public class MockPageContext extends PageContext {
}
@Override
@Nullable
public ELContext getELContext() {
public @Nullable ELContext getELContext() {
return null;
}
@@ -294,8 +289,7 @@ public class MockPageContext extends PageContext {
}
@Override
@Nullable
public Exception getException() {
public @Nullable Exception getException() {
return null;
}

View File

@@ -23,10 +23,10 @@ import java.util.Collection;
import java.util.Collections;
import jakarta.servlet.http.Part;
import org.jspecify.annotations.Nullable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -42,8 +42,7 @@ public class MockPart implements Part {
private final String name;
@Nullable
private final String filename;
private final @Nullable String filename;
private final byte[] content;
@@ -54,7 +53,7 @@ public class MockPart implements Part {
* Constructor for a part with a name and content only.
* @see #getHeaders()
*/
public MockPart(String name, @Nullable byte[] content) {
public MockPart(String name, byte @Nullable [] content) {
this(name, null, content);
}
@@ -62,7 +61,7 @@ public class MockPart implements Part {
* Constructor for a part with a name, filename, and content.
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
public MockPart(String name, @Nullable String filename, byte @Nullable [] content) {
this(name, filename, content, null);
}
@@ -71,7 +70,7 @@ public class MockPart implements Part {
* @since 6.1.2
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) {
public MockPart(String name, @Nullable String filename, byte @Nullable [] content, @Nullable MediaType contentType) {
Assert.hasLength(name, "'name' must not be empty");
this.name = name;
this.filename = filename;
@@ -87,14 +86,12 @@ public class MockPart implements Part {
}
@Override
@Nullable
public String getSubmittedFileName() {
public @Nullable String getSubmittedFileName() {
return this.filename;
}
@Override
@Nullable
public String getContentType() {
public @Nullable String getContentType() {
MediaType contentType = this.headers.getContentType();
return (contentType != null ? contentType.toString() : null);
}
@@ -120,8 +117,7 @@ public class MockPart implements Part {
}
@Override
@Nullable
public String getHeader(String name) {
public @Nullable String getHeader(String name) {
return this.headers.getFirst(name);
}

View File

@@ -23,8 +23,8 @@ import java.util.Map;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -93,8 +93,7 @@ public class MockServletConfig implements ServletConfig {
}
@Override
@Nullable
public String getInitParameter(String name) {
public @Nullable String getInitParameter(String name) {
Assert.notNull(name, "Parameter name must not be null");
return this.initParameters.get(name);
}

View File

@@ -43,13 +43,13 @@ import jakarta.servlet.SessionTrackingMode;
import jakarta.servlet.descriptor.JspConfigDescriptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -132,18 +132,15 @@ public class MockServletContext implements ServletContext {
private final Set<String> declaredRoles = new LinkedHashSet<>();
@Nullable
private Set<SessionTrackingMode> sessionTrackingModes;
private @Nullable Set<SessionTrackingMode> sessionTrackingModes;
private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig();
private int sessionTimeout;
@Nullable
private String requestCharacterEncoding;
private @Nullable String requestCharacterEncoding;
@Nullable
private String responseCharacterEncoding;
private @Nullable String responseCharacterEncoding;
private final Map<String, FilterRegistration> filterRegistrations = new LinkedHashMap<>();
@@ -226,8 +223,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public ServletContext getContext(String contextPath) {
public @Nullable ServletContext getContext(String contextPath) {
if (this.contextPath.equals(contextPath)) {
return this;
}
@@ -271,8 +267,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public String getMimeType(String filePath) {
public @Nullable String getMimeType(String filePath) {
String extension = StringUtils.getFilenameExtension(filePath);
if (this.mimeTypes.containsKey(extension)) {
return this.mimeTypes.get(extension).toString();
@@ -295,8 +290,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public Set<String> getResourcePaths(String path) {
public @Nullable Set<String> getResourcePaths(String path) {
String actualPath = (path.endsWith("/") ? path : path + "/");
String resourceLocation = getResourceLocation(actualPath);
Resource resource = null;
@@ -327,8 +321,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public URL getResource(String path) throws MalformedURLException {
public @Nullable URL getResource(String path) throws MalformedURLException {
String resourceLocation = getResourceLocation(path);
Resource resource = null;
try {
@@ -351,8 +344,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public InputStream getResourceAsStream(String path) {
public @Nullable InputStream getResourceAsStream(String path) {
String resourceLocation = getResourceLocation(path);
Resource resource = null;
try {
@@ -379,8 +371,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public RequestDispatcher getNamedDispatcher(String path) {
public @Nullable RequestDispatcher getNamedDispatcher(String path) {
return this.namedRequestDispatchers.get(path);
}
@@ -446,8 +437,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public String getRealPath(String path) {
public @Nullable String getRealPath(String path) {
String resourceLocation = getResourceLocation(path);
Resource resource = null;
try {
@@ -469,8 +459,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public String getInitParameter(String name) {
public @Nullable String getInitParameter(String name) {
Assert.notNull(name, "Parameter name must not be null");
return this.initParameters.get(name);
}
@@ -496,8 +485,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public Object getAttribute(String name) {
public @Nullable Object getAttribute(String name) {
Assert.notNull(name, "Attribute name must not be null");
return this.attributes.get(name);
}
@@ -534,8 +522,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public ClassLoader getClassLoader() {
public @Nullable ClassLoader getClassLoader() {
return ClassUtils.getDefaultClassLoader();
}
@@ -590,8 +577,7 @@ public class MockServletContext implements ServletContext {
}
@Override // on Servlet 4.0
@Nullable
public String getRequestCharacterEncoding() {
public @Nullable String getRequestCharacterEncoding() {
return this.requestCharacterEncoding;
}
@@ -601,8 +587,7 @@ public class MockServletContext implements ServletContext {
}
@Override // on Servlet 4.0
@Nullable
public String getResponseCharacterEncoding() {
public @Nullable String getResponseCharacterEncoding() {
return this.responseCharacterEncoding;
}
@@ -615,8 +600,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public FilterRegistration getFilterRegistration(String filterName) {
public @Nullable FilterRegistration getFilterRegistration(String filterName) {
return this.filterRegistrations.get(filterName);
}
@@ -665,8 +649,7 @@ public class MockServletContext implements ServletContext {
* @see jakarta.servlet.ServletContext#getServletRegistration(java.lang.String)
*/
@Override
@Nullable
public ServletRegistration getServletRegistration(String servletName) {
public @Nullable ServletRegistration getServletRegistration(String servletName) {
return null;
}

View File

@@ -21,8 +21,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import jakarta.servlet.SessionCookieConfig;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Mock implementation of the {@link jakarta.servlet.SessionCookieConfig} interface.
@@ -33,17 +32,13 @@ import org.springframework.lang.Nullable;
*/
public class MockSessionCookieConfig implements SessionCookieConfig {
@Nullable
private String name;
private @Nullable String name;
@Nullable
private String domain;
private @Nullable String domain;
@Nullable
private String path;
private @Nullable String path;
@Nullable
private String comment;
private @Nullable String comment;
private boolean httpOnly;
@@ -60,8 +55,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
}
@Override
@Nullable
public String getName() {
public @Nullable String getName() {
return this.name;
}
@@ -71,8 +65,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
}
@Override
@Nullable
public String getDomain() {
public @Nullable String getDomain() {
return this.domain;
}
@@ -82,8 +75,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
}
@Override
@Nullable
public String getPath() {
public @Nullable String getPath() {
return this.path;
}
@@ -95,8 +87,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
@SuppressWarnings("removal")
@Override
@Nullable
public String getComment() {
public @Nullable String getComment() {
return this.comment;
}
@@ -136,8 +127,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
}
@Override
@Nullable
public String getAttribute(String name) {
public @Nullable String getAttribute(String name) {
return this.attributes.get(name);
}

View File

@@ -24,8 +24,8 @@ import jakarta.servlet.Servlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -42,14 +42,11 @@ import org.springframework.util.Assert;
*/
public class PassThroughFilterChain implements FilterChain {
@Nullable
private Filter filter;
private @Nullable Filter filter;
@Nullable
private FilterChain nextFilterChain;
private @Nullable FilterChain nextFilterChain;
@Nullable
private Servlet servlet;
private @Nullable Servlet servlet;
/**

View File

@@ -4,9 +4,7 @@
*
* <p>Useful for testing web contexts and controllers.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.web;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -31,6 +31,7 @@ import java.util.OptionalLong;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -44,7 +45,6 @@ import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -76,8 +76,7 @@ public final class MockServerRequest implements ServerRequest {
private final MultiValueMap<String, HttpCookie> cookies;
@Nullable
private final Object body;
private final @Nullable Object body;
private final Map<String, Object> attributes;
@@ -85,22 +84,17 @@ public final class MockServerRequest implements ServerRequest {
private final Map<String, String> pathVariables;
@Nullable
private final WebSession session;
private final @Nullable WebSession session;
@Nullable
private final Principal principal;
private final @Nullable Principal principal;
@Nullable
private final InetSocketAddress remoteAddress;
private final @Nullable InetSocketAddress remoteAddress;
@Nullable
private final InetSocketAddress localAddress;
private final @Nullable InetSocketAddress localAddress;
private final List<HttpMessageReader<?>> messageReaders;
@Nullable
private final ServerWebExchange exchange;
private final @Nullable ServerWebExchange exchange;
private MockServerRequest(HttpMethod method, URI uri, String contextPath, MockHeaders headers,
@@ -345,8 +339,7 @@ public final class MockServerRequest implements ServerRequest {
private MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
@Nullable
private Object body;
private @Nullable Object body;
private Map<String, Object> attributes = new ConcurrentHashMap<>();
@@ -354,22 +347,17 @@ public final class MockServerRequest implements ServerRequest {
private Map<String, String> pathVariables = new LinkedHashMap<>();
@Nullable
private WebSession session;
private @Nullable WebSession session;
@Nullable
private Principal principal;
private @Nullable Principal principal;
@Nullable
private InetSocketAddress remoteAddress;
private @Nullable InetSocketAddress remoteAddress;
@Nullable
private InetSocketAddress localAddress;
private @Nullable InetSocketAddress localAddress;
private List<HttpMessageReader<?>> messageReaders = HandlerStrategies.withDefaults().messageReaders();
@Nullable
private ServerWebExchange exchange;
private @Nullable ServerWebExchange exchange;
@Override
public Builder method(HttpMethod method) {
@@ -569,8 +557,7 @@ public final class MockServerRequest implements ServerRequest {
}
@Override
@Nullable
public InetSocketAddress host() {
public @Nullable InetSocketAddress host() {
return delegate().getHost();
}

View File

@@ -4,9 +4,7 @@
* <p>Useful for testing router and handler functions.
*
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.web.reactive.function.server;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,10 +16,10 @@
package org.springframework.mock.web.server;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.lang.Nullable;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.server.WebSession;
@@ -98,8 +98,7 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
private final MockServerHttpRequest request;
@Nullable
private WebSessionManager sessionManager;
private @Nullable WebSessionManager sessionManager;
public Builder(MockServerHttpRequest request) {
this.request = request;

View File

@@ -21,9 +21,9 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.session.InMemoryWebSessionStore;

View File

@@ -1,9 +1,7 @@
/**
* Mock implementations of Spring's reactive server web API abstractions.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.mock.web.server;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,7 +16,7 @@
package org.springframework.test.annotation;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* <p>
@@ -49,7 +49,6 @@ public interface ProfileValueSource {
* @return the String value of the <em>profile value</em>, or {@code null}
* if there is no <em>profile value</em> with that key
*/
@Nullable
String get(String key);
@Nullable String get(String key);
}

View File

@@ -20,10 +20,10 @@ import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;

View File

@@ -1,9 +1,7 @@
/**
* Support classes for annotation-driven tests.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,8 +16,9 @@
package org.springframework.test.context;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
/**
* Strategy for components that process failures related to application contexts

View File

@@ -23,10 +23,10 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.core.log.LogMessage;
import org.springframework.lang.Nullable;
import org.springframework.test.context.TestContextAnnotationUtils.AnnotationDescriptor;
import org.springframework.util.ClassUtils;
@@ -168,8 +168,7 @@ public abstract class BootstrapUtils {
}
}
@Nullable
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) {
private static @Nullable Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) {
Set<BootstrapWith> annotations = new LinkedHashSet<>();
AnnotationDescriptor<BootstrapWith> descriptor =
TestContextAnnotationUtils.findAnnotationDescriptor(testClass, BootstrapWith.class);

View File

@@ -16,9 +16,10 @@
package org.springframework.test.context;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
/**

View File

@@ -20,13 +20,13 @@ import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.style.DefaultToStringStyler;
import org.springframework.core.style.SimpleValueStyler;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -63,8 +63,7 @@ public class ContextConfigurationAttributes {
private final boolean inheritInitializers;
@Nullable
private final String name;
private final @Nullable String name;
private final Class<? extends ContextLoader> contextLoaderClass;
@@ -305,8 +304,7 @@ public class ContextConfigurationAttributes {
* @since 3.2.2
* @see ContextConfiguration#name()
*/
@Nullable
public String getName() {
public @Nullable String getName() {
return this.name;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.test.context;
import java.util.List;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Factory for creating {@link ContextCustomizer ContextCustomizers}.
@@ -56,7 +56,6 @@ public interface ContextCustomizerFactory {
* @return a {@link ContextCustomizer} or {@code null} if no customizer should
* be used
*/
@Nullable
ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes);
@Nullable ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes);
}

View File

@@ -21,8 +21,8 @@ import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -40,8 +40,7 @@ final class DefaultMethodInvoker implements MethodInvoker {
@Override
@Nullable
public Object invoke(Method method, @Nullable Object target) throws Exception {
public @Nullable Object invoke(Method method, @Nullable Object target) throws Exception {
Assert.notNull(method, "Method must not be null");
try {

View File

@@ -23,13 +23,14 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.core.io.support.PropertySourceDescriptor;
import org.springframework.core.style.DefaultToStringStyler;
import org.springframework.core.style.SimpleValueStyler;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -102,11 +103,9 @@ public class MergedContextConfiguration implements Serializable {
private final ContextLoader contextLoader;
@Nullable
private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate;
private final @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate;
@Nullable
private final MergedContextConfiguration parent;
private final @Nullable MergedContextConfiguration parent;
/**
@@ -118,8 +117,8 @@ public class MergedContextConfiguration implements Serializable {
* @param activeProfiles the merged active bean definition profiles
* @param contextLoader the resolved {@code ContextLoader}
*/
public MergedContextConfiguration(Class<?> testClass, @Nullable String[] locations, @Nullable Class<?>[] classes,
@Nullable String[] activeProfiles, ContextLoader contextLoader) {
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes,
String @Nullable [] activeProfiles, ContextLoader contextLoader) {
this(testClass, locations, classes, null, activeProfiles, contextLoader);
}
@@ -134,9 +133,9 @@ public class MergedContextConfiguration implements Serializable {
* @param activeProfiles the merged active bean definition profiles
* @param contextLoader the resolved {@code ContextLoader}
*/
public MergedContextConfiguration(Class<?> testClass, @Nullable String[] locations, @Nullable Class<?>[] classes,
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes,
@Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses,
@Nullable String[] activeProfiles, ContextLoader contextLoader) {
String @Nullable [] activeProfiles, ContextLoader contextLoader) {
this(testClass, locations, classes, contextInitializerClasses, activeProfiles, contextLoader, null, null);
}
@@ -155,9 +154,9 @@ public class MergedContextConfiguration implements Serializable {
* @param parent the parent configuration or {@code null} if there is no parent
* @since 3.2.2
*/
public MergedContextConfiguration(Class<?> testClass, @Nullable String[] locations, @Nullable Class<?>[] classes,
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes,
@Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses,
@Nullable String[] activeProfiles, ContextLoader contextLoader,
String @Nullable [] activeProfiles, ContextLoader contextLoader,
@Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate,
@Nullable MergedContextConfiguration parent) {
@@ -204,10 +203,10 @@ public class MergedContextConfiguration implements Serializable {
* {@link #MergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)}
*/
@Deprecated(since = "6.1")
public MergedContextConfiguration(Class<?> testClass, @Nullable String[] locations, @Nullable Class<?>[] classes,
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes,
@Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses,
@Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations,
@Nullable String[] propertySourceProperties, ContextLoader contextLoader,
String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations,
String @Nullable [] propertySourceProperties, ContextLoader contextLoader,
@Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate,
@Nullable MergedContextConfiguration parent) {
@@ -244,10 +243,10 @@ public class MergedContextConfiguration implements Serializable {
* {@link #MergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)}
*/
@Deprecated(since = "6.1")
public MergedContextConfiguration(Class<?> testClass, @Nullable String[] locations, @Nullable Class<?>[] classes,
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes,
@Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses,
@Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations,
@Nullable String[] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers,
String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations,
String @Nullable [] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers,
ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate,
@Nullable MergedContextConfiguration parent) {
@@ -280,10 +279,10 @@ public class MergedContextConfiguration implements Serializable {
* @param parent the parent configuration or {@code null} if there is no parent
* @since 6.1
*/
public MergedContextConfiguration(Class<?> testClass, @Nullable String[] locations, @Nullable Class<?>[] classes,
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes,
@Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses,
@Nullable String[] activeProfiles, List<PropertySourceDescriptor> propertySourceDescriptors,
@Nullable String[] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers,
String @Nullable [] activeProfiles, List<PropertySourceDescriptor> propertySourceDescriptors,
String @Nullable [] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers,
ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate,
@Nullable MergedContextConfiguration parent) {
@@ -443,8 +442,7 @@ public class MergedContextConfiguration implements Serializable {
* @since 3.2.2
* @see #getParentApplicationContext()
*/
@Nullable
public MergedContextConfiguration getParent() {
public @Nullable MergedContextConfiguration getParent() {
return this.parent;
}
@@ -457,8 +455,7 @@ public class MergedContextConfiguration implements Serializable {
* @since 3.2.2
* @see #getParent()
*/
@Nullable
public ApplicationContext getParentApplicationContext() {
public @Nullable ApplicationContext getParentApplicationContext() {
if (this.parent == null) {
return null;
}
@@ -575,11 +572,11 @@ public class MergedContextConfiguration implements Serializable {
}
protected static String[] processStrings(@Nullable String[] array) {
protected static String[] processStrings(String @Nullable [] array) {
return (array != null ? array : EMPTY_STRING_ARRAY);
}
private static Class<?>[] processClasses(@Nullable Class<?>[] classes) {
private static Class<?>[] processClasses(Class<?> @Nullable [] classes) {
return (classes != null ? classes : EMPTY_CLASS_ARRAY);
}
@@ -597,7 +594,7 @@ public class MergedContextConfiguration implements Serializable {
Collections.unmodifiableSet(contextCustomizers) : EMPTY_CONTEXT_CUSTOMIZERS);
}
private static String[] processActiveProfiles(@Nullable String[] activeProfiles) {
private static String[] processActiveProfiles(String @Nullable [] activeProfiles) {
if (activeProfiles == null) {
return EMPTY_STRING_ARRAY;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.test.context;
import java.lang.reflect.Method;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@code MethodInvoker} defines a generic API for invoking a {@link Method}
@@ -66,7 +66,6 @@ public interface MethodInvoker {
* @return the value returned from the method invocation, potentially {@code null}
* @throws Exception if any error occurs
*/
@Nullable
Object invoke(Method method, @Nullable Object target) throws Exception;
@Nullable Object invoke(Method method, @Nullable Object target) throws Exception;
}

View File

@@ -26,8 +26,7 @@ import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@code @NestedTestConfiguration} is an annotation that can be applied to a test
@@ -161,8 +160,7 @@ public @interface NestedTestConfiguration {
* @return the corresponding enum constant or {@code null} if not found
* @see EnclosingConfiguration#valueOf(String)
*/
@Nullable
public static EnclosingConfiguration from(@Nullable String name) {
public static @Nullable EnclosingConfiguration from(@Nullable String name) {
if (name == null) {
return null;
}

View File

@@ -26,8 +26,7 @@ import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@code @TestConstructor} is an annotation that can be applied to a test class
@@ -151,8 +150,7 @@ public @interface TestConstructor {
* @since 5.3
* @see AutowireMode#valueOf(String)
*/
@Nullable
public static AutowireMode from(@Nullable String name) {
public static @Nullable AutowireMode from(@Nullable String name) {
if (name == null) {
return null;
}

View File

@@ -20,10 +20,11 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.AttributeAccessor;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
/**
@@ -125,8 +126,7 @@ public interface TestContext extends AttributeAccessor, Serializable {
* @return the exception that was thrown, or {@code null} if no exception was thrown
* @see #updateState(Object, Method, Throwable)
*/
@Nullable
Throwable getTestException();
@Nullable Throwable getTestException();
/**
* Call this method to signal that the {@linkplain ApplicationContext application

View File

@@ -22,6 +22,8 @@ import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.springframework.core.SpringProperties;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
@@ -34,7 +36,6 @@ import org.springframework.core.annotation.RepeatableContainers;
import org.springframework.core.style.DefaultToStringStyler;
import org.springframework.core.style.SimpleValueStyler;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -78,8 +79,7 @@ public abstract class TestContextAnnotationUtils {
private static final ConcurrentLruCache<Class<?>, EnclosingConfiguration> cachedEnclosingConfigurationModes =
new ConcurrentLruCache<>(32, TestContextAnnotationUtils::lookUpEnclosingConfiguration);
@Nullable
private static volatile EnclosingConfiguration defaultEnclosingConfigurationMode;
private static volatile @Nullable EnclosingConfiguration defaultEnclosingConfigurationMode;
/**
@@ -123,13 +123,11 @@ public abstract class TestContextAnnotationUtils {
* @see #findAnnotationDescriptor(Class, Class)
* @see #searchEnclosingClass(Class)
*/
@Nullable
public static <T extends Annotation> T findMergedAnnotation(Class<?> clazz, Class<T> annotationType) {
public static <T extends Annotation> @Nullable T findMergedAnnotation(Class<?> clazz, Class<T> annotationType) {
return findMergedAnnotation(clazz, annotationType, TestContextAnnotationUtils::searchEnclosingClass);
}
@Nullable
private static <T extends Annotation> T findMergedAnnotation(Class<?> clazz, Class<T> annotationType,
private static <T extends Annotation> @Nullable T findMergedAnnotation(Class<?> clazz, Class<T> annotationType,
Predicate<Class<?>> searchEnclosingClass) {
return MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY)
@@ -215,8 +213,7 @@ public abstract class TestContextAnnotationUtils {
* otherwise {@code null}
* @see #findAnnotationDescriptorForTypes(Class, Class...)
*/
@Nullable
public static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDescriptor(
public static <T extends Annotation> @Nullable AnnotationDescriptor<T> findAnnotationDescriptor(
Class<?> clazz, Class<T> annotationType) {
Assert.notNull(annotationType, "Annotation type must not be null");
@@ -236,8 +233,7 @@ public abstract class TestContextAnnotationUtils {
* @return the corresponding annotation descriptor if the annotation was found;
* otherwise {@code null}
*/
@Nullable
private static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDescriptor(
private static <T extends Annotation> @Nullable AnnotationDescriptor<T> findAnnotationDescriptor(
@Nullable Class<?> clazz, Class<T> annotationType, Predicate<Class<?>> searchEnclosingClass,
Set<Annotation> visited) {
@@ -322,8 +318,7 @@ public abstract class TestContextAnnotationUtils {
* @see #findAnnotationDescriptor(Class, Class)
*/
@SuppressWarnings("unchecked")
@Nullable
public static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(
public static @Nullable UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(
Class<?> clazz, Class<? extends Annotation>... annotationTypes) {
assertNonEmptyAnnotationTypeArray(annotationTypes, "The list of annotation types must not be empty");
@@ -340,8 +335,7 @@ public abstract class TestContextAnnotationUtils {
* @return the corresponding annotation descriptor if one of the annotations
* was found; otherwise {@code null}
*/
@Nullable
private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(@Nullable Class<?> clazz,
private static @Nullable UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(@Nullable Class<?> clazz,
Class<? extends Annotation>[] annotationTypes, Set<Annotation> visited) {
if (clazz == null || Object.class == clazz) {
@@ -556,8 +550,7 @@ public abstract class TestContextAnnotationUtils {
* @return the next corresponding annotation descriptor if the annotation
* was found; otherwise {@code null}
*/
@Nullable
public AnnotationDescriptor<T> next() {
public @Nullable AnnotationDescriptor<T> next() {
// Declared on a superclass?
AnnotationDescriptor<T> descriptor =
findAnnotationDescriptor(getRootDeclaringClass().getSuperclass(), getAnnotationType());
@@ -635,8 +628,7 @@ public abstract class TestContextAnnotationUtils {
* @see AnnotationDescriptor#next()
*/
@Override
@Nullable
public UntypedAnnotationDescriptor next() {
public @Nullable UntypedAnnotationDescriptor next() {
// Declared on a superclass?
UntypedAnnotationDescriptor descriptor =
findAnnotationDescriptorForTypes(getRootDeclaringClass().getSuperclass(), this.annotationTypes);

View File

@@ -25,8 +25,8 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;

View File

@@ -16,8 +16,9 @@
package org.springframework.test.context.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.lang.Nullable;
/**
* Holder for metadata specific to ahead-of-time (AOT) support in the <em>Spring
@@ -117,8 +118,7 @@ public interface AotTestAttributes {
* @see #getBoolean(String)
* @see #setAttribute(String, String)
*/
@Nullable
String getString(String name);
@Nullable String getString(String name);
/**
* Retrieve the attribute value for the given name as a {@code boolean}.

View File

@@ -19,8 +19,9 @@ package org.springframework.test.context.aot;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.lang.Nullable;
/**
* Factory for {@link AotTestAttributes}.
@@ -30,8 +31,7 @@ import org.springframework.lang.Nullable;
*/
final class AotTestAttributesFactory {
@Nullable
private static volatile Map<String, String> attributes;
private static volatile @Nullable Map<String, String> attributes;
private AotTestAttributesFactory() {

View File

@@ -19,10 +19,11 @@ package org.springframework.test.context.aot;
import java.util.Map;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.lang.Nullable;
/**
* {@code AotTestContextInitializers} provides mappings from test classes to
@@ -76,8 +77,7 @@ public class AotTestContextInitializers {
* @see #isSupportedTestClass(Class)
* @see #getContextInitializerClass(Class)
*/
@Nullable
public ApplicationContextInitializer<ConfigurableApplicationContext> getContextInitializer(Class<?> testClass) {
public @Nullable ApplicationContextInitializer<ConfigurableApplicationContext> getContextInitializer(Class<?> testClass) {
Supplier<ApplicationContextInitializer<ConfigurableApplicationContext>> supplier =
this.contextInitializers.get(testClass.getName());
return (supplier != null ? supplier.get() : null);
@@ -91,8 +91,7 @@ public class AotTestContextInitializers {
* @see #isSupportedTestClass(Class)
* @see #getContextInitializer(Class)
*/
@Nullable
public Class<ApplicationContextInitializer<?>> getContextInitializerClass(Class<?> testClass) {
public @Nullable Class<ApplicationContextInitializer<?>> getContextInitializerClass(Class<?> testClass) {
return this.contextInitializerClasses.get(testClass.getName());
}

View File

@@ -19,10 +19,11 @@ package org.springframework.test.context.aot;
import java.util.Map;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.lang.Nullable;
/**
* Factory for {@link AotTestContextInitializers}.
@@ -32,11 +33,9 @@ import org.springframework.lang.Nullable;
*/
final class AotTestContextInitializersFactory {
@Nullable
private static volatile Map<String, Supplier<ApplicationContextInitializer<ConfigurableApplicationContext>>> contextInitializers;
private static volatile @Nullable Map<String, Supplier<ApplicationContextInitializer<ConfigurableApplicationContext>>> contextInitializers;
@Nullable
private static volatile Map<String, Class<ApplicationContextInitializer<?>>> contextInitializerClasses;
private static volatile @Nullable Map<String, Class<ApplicationContextInitializer<?>>> contextInitializerClasses;
private AotTestContextInitializersFactory() {

View File

@@ -18,8 +18,9 @@ package org.springframework.test.context.aot;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -54,8 +55,7 @@ class DefaultAotTestAttributes implements AotTestAttributes {
}
@Override
@Nullable
public String getString(String name) {
public @Nullable String getString(String name) {
return this.attributes.get(name);
}

View File

@@ -16,11 +16,12 @@
package org.springframework.test.context.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.ClassNameGenerator;
import org.springframework.aot.generate.DefaultGenerationContext;
import org.springframework.aot.generate.GeneratedFiles;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.lang.Nullable;
/**
* Extension of {@link DefaultGenerationContext} with a custom implementation of
@@ -31,8 +32,7 @@ import org.springframework.lang.Nullable;
*/
class TestContextGenerationContext extends DefaultGenerationContext {
@Nullable
private final String featureName;
private final @Nullable String featureName;
/**

View File

@@ -1,9 +1,7 @@
/**
* Ahead-of-time (AOT) support for the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.aot;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -22,6 +22,8 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -39,7 +41,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -293,8 +294,7 @@ class BeanOverrideBeanFactoryPostProcessor implements BeanFactoryPostProcessor,
this.beanOverrideRegistry.registerBeanOverrideHandler(handler, beanName);
}
@Nullable
private String getBeanNameForType(ConfigurableListableBeanFactory beanFactory, BeanOverrideHandler handler,
private @Nullable String getBeanNameForType(ConfigurableListableBeanFactory beanFactory, BeanOverrideHandler handler,
boolean requireExistingBean) {
Field field = handler.getField();
@@ -368,8 +368,7 @@ class BeanOverrideBeanFactoryPostProcessor implements BeanFactoryPostProcessor,
* @return the name of the primary candidate, or {@code null} if none found
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#determinePrimaryCandidate(Map, Class)
*/
@Nullable
private static String determinePrimaryCandidate(
private static @Nullable String determinePrimaryCandidate(
ConfigurableListableBeanFactory beanFactory, Set<String> candidateBeanNames, Class<?> beanType) {
if (candidateBeanNames.isEmpty()) {

View File

@@ -20,7 +20,8 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.ContextCustomizerFactory;
import org.springframework.test.context.TestContextAnnotationUtils;
@@ -39,8 +40,7 @@ import org.springframework.util.Assert;
class BeanOverrideContextCustomizerFactory implements ContextCustomizerFactory {
@Override
@Nullable
public BeanOverrideContextCustomizer createContextCustomizer(Class<?> testClass,
public @Nullable BeanOverrideContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) {
Set<BeanOverrideHandler> handlers = new LinkedHashSet<>();

View File

@@ -28,6 +28,8 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.SingletonBeanRegistry;
@@ -35,7 +37,6 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -76,8 +77,7 @@ public abstract class BeanOverrideHandler {
private final ResolvableType beanType;
@Nullable
private final String beanName;
private final @Nullable String beanName;
private final BeanOverrideStrategy strategy;
@@ -145,8 +145,7 @@ public abstract class BeanOverrideHandler {
* Get the bean name to override, or {@code null} to look for a single
* matching bean of type {@link #getBeanType()}.
*/
@Nullable
public final String getBeanName() {
public final @Nullable String getBeanName() {
return this.beanName;
}

View File

@@ -21,10 +21,11 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.ResolvableType;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.bean.override.BeanOverrideHandler;
import org.springframework.test.context.bean.override.BeanOverrideStrategy;
import org.springframework.util.ReflectionUtils;

View File

@@ -3,9 +3,7 @@
* in the test class. This allows defining a custom instance for the bean
* straight from the test class.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.bean.override.convention;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -18,10 +18,11 @@ package org.springframework.test.context.bean.override.mockito;
import java.lang.reflect.Field;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.SingletonBeanRegistry;
import org.springframework.core.ResolvableType;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.bean.override.BeanOverrideHandler;
import org.springframework.test.context.bean.override.BeanOverrideStrategy;

View File

@@ -23,6 +23,7 @@ import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.mockito.Answers;
import org.mockito.MockSettings;
import org.mockito.Mockito;
@@ -30,7 +31,6 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.ResolvableType;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.bean.override.BeanOverrideHandler;
import org.springframework.test.context.bean.override.BeanOverrideStrategy;
import org.springframework.util.Assert;

View File

@@ -22,6 +22,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactory;
@@ -32,7 +33,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.util.ClassUtils;
@@ -69,8 +69,7 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
* @see #mockitoPresent
* @see #isEnabled()
*/
@Nullable
private static volatile Boolean mockitoInitialized;
private static volatile @Nullable Boolean mockitoInitialized;
/**
@@ -126,8 +125,7 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
}
}
@Nullable
private static Object getBean(ConfigurableListableBeanFactory beanFactory, String beanName) {
private static @Nullable Object getBean(ConfigurableListableBeanFactory beanFactory, String beanName) {
try {
if (isStandardBeanOrSingletonFactoryBean(beanFactory, beanName)) {
return beanFactory.getBean(beanName);

View File

@@ -19,6 +19,7 @@ package org.springframework.test.context.bean.override.mockito;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import org.jspecify.annotations.Nullable;
import org.mockito.AdditionalAnswers;
import org.mockito.MockSettings;
import org.mockito.Mockito;
@@ -27,7 +28,6 @@ import org.mockito.listeners.VerificationStartedListener;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.test.context.bean.override.BeanOverrideHandler;
import org.springframework.test.context.bean.override.BeanOverrideStrategy;
import org.springframework.util.Assert;

View File

@@ -1,9 +1,7 @@
/**
* Bean overriding mechanism based on Mockito mocking and spying.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.bean.override.mockito;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Support case-by-case Bean overriding in Spring tests.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.bean.override;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -18,11 +18,12 @@ package org.springframework.test.context.cache;
import java.util.Collections;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.core.style.DefaultToStringStyler;
import org.springframework.core.style.SimpleValueStyler;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.MergedContextConfiguration;

View File

@@ -16,8 +16,9 @@
package org.springframework.test.context.cache;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.MergedContextConfiguration;
@@ -95,8 +96,7 @@ public interface ContextCache {
* if not found in the cache
* @see #remove
*/
@Nullable
ApplicationContext get(MergedContextConfiguration key);
@Nullable ApplicationContext get(MergedContextConfiguration key);
/**
* Explicitly add an {@code ApplicationContext} instance to the cache

View File

@@ -20,13 +20,13 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.AotDetector;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.ApplicationContextFailureProcessor;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;

View File

@@ -28,11 +28,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.util.Assert;
@@ -121,8 +121,7 @@ public class DefaultContextCache implements ContextCache {
}
@Override
@Nullable
public ApplicationContext get(MergedContextConfiguration key) {
public @Nullable ApplicationContext get(MergedContextConfiguration key) {
Assert.notNull(key, "Key must not be null");
ApplicationContext context = this.contextMap.get(key);
if (context == null) {

View File

@@ -1,9 +1,7 @@
/**
* Support for context caching within the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.cache;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,7 +16,8 @@
package org.springframework.test.context.event;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@@ -57,8 +58,7 @@ public abstract class ApplicationEventsHolder {
* Get the {@link ApplicationEvents} for the current thread.
* @return the current {@code ApplicationEvents}, or {@code null} if not registered
*/
@Nullable
public static ApplicationEvents getApplicationEvents() {
public static @Nullable ApplicationEvents getApplicationEvents() {
return applicationEvents.get();
}

View File

@@ -1,9 +1,7 @@
/**
* Test execution event annotations for the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.event.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Test event support classes for the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.event;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -20,13 +20,14 @@ import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.ReflectionHints;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint;
import org.springframework.aot.hint.TypeReference;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**

View File

@@ -2,9 +2,7 @@
* Support for registering hints for reflection and resources in the
* <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.hint;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,13 +19,14 @@ package org.springframework.test.context.jdbc;
import java.lang.reflect.Array;
import java.util.Arrays;
import org.jspecify.annotations.Nullable;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.style.DefaultToStringStyler;
import org.springframework.core.style.SimpleValueStyler;
import org.springframework.core.style.ToStringCreator;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.lang.Nullable;
import org.springframework.test.context.TestContextAnnotationUtils;
import org.springframework.test.context.jdbc.SqlConfig.ErrorMode;
import org.springframework.test.context.jdbc.SqlConfig.TransactionMode;

View File

@@ -26,6 +26,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.context.ApplicationContext;
@@ -35,7 +36,6 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestContextAnnotationUtils;
import org.springframework.test.context.aot.AotTestExecutionListener;
@@ -238,16 +238,14 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
/**
* Get the {@code @SqlMergeMode} annotation declared on the supplied class.
*/
@Nullable
private SqlMergeMode getSqlMergeModeFor(Class<?> clazz) {
private @Nullable SqlMergeMode getSqlMergeModeFor(Class<?> clazz) {
return TestContextAnnotationUtils.findMergedAnnotation(clazz, SqlMergeMode.class);
}
/**
* Get the {@code @SqlMergeMode} annotation declared on the supplied method.
*/
@Nullable
private SqlMergeMode getSqlMergeModeFor(Method method) {
private @Nullable SqlMergeMode getSqlMergeModeFor(Method method) {
return AnnotatedElementUtils.findMergedAnnotation(method, SqlMergeMode.class);
}
@@ -386,8 +384,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
.equals(TransactionSynchronizationUtils.unwrapResourceIfNecessary(ds2));
}
@Nullable
private DataSource getDataSourceFromTransactionManager(PlatformTransactionManager transactionManager) {
private @Nullable DataSource getDataSourceFromTransactionManager(PlatformTransactionManager transactionManager) {
try {
Method getDataSourceMethod = transactionManager.getClass().getMethod("getDataSource");
Object obj = ReflectionUtils.invokeMethod(getDataSourceMethod, transactionManager);

View File

@@ -2,9 +2,7 @@
* JDBC support classes for the <em>Spring TestContext Framework</em>,
* including support for declarative SQL script execution via {@code @Sql}.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.jdbc;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -24,6 +24,7 @@ import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -50,7 +51,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.core.annotation.RepeatableContainers;
import org.springframework.lang.Nullable;
import org.springframework.test.context.MethodInvoker;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.TestContextAnnotationUtils;
@@ -330,8 +330,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* @see ParameterResolutionDelegate#resolveDependency
*/
@Override
@Nullable
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
public @Nullable Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
Parameter parameter = parameterContext.getParameter();
int index = parameterContext.getIndex();
Class<?> testClass = extensionContext.getRequiredTestClass();

View File

@@ -2,9 +2,7 @@
* Core support for integrating the <em>Spring TestContext Framework</em>
* with the JUnit Jupiter extension model in JUnit 5.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.junit.jupiter;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -2,9 +2,7 @@
* Web support for integrating the <em>Spring TestContext Framework</em>
* with the JUnit Jupiter extension model in JUnit 5.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.junit.jupiter.web;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -18,11 +18,11 @@ package org.springframework.test.context.junit4;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestContextManager;
@@ -75,8 +75,7 @@ public abstract class AbstractJUnit4SpringContextTests implements ApplicationCon
* The {@link ApplicationContext} that was injected into this test instance
* via {@link #setApplicationContext(ApplicationContext)}.
*/
@Nullable
protected ApplicationContext applicationContext;
protected @Nullable ApplicationContext applicationContext;
/**

View File

@@ -18,13 +18,14 @@ package org.springframework.test.context.junit4;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.jdbc.JdbcTestUtils;
@@ -87,8 +88,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
*/
protected final JdbcTemplate jdbcTemplate = new JdbcTemplate();
@Nullable
private String sqlScriptEncoding;
private @Nullable String sqlScriptEncoding;
/**

View File

@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.internal.runners.model.ReflectiveCallable;
@@ -35,7 +36,6 @@ import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.ProfileValueUtils;
import org.springframework.test.annotation.TestAnnotationUtils;
import org.springframework.test.context.TestContextManager;
@@ -346,8 +346,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
* <p>Can be overridden by subclasses.
* @return the expected exception, or {@code null} if none was specified
*/
@Nullable
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
protected @Nullable Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
Test test = frameworkMethod.getAnnotation(Test.class);
return (test != null && test.expected() != Test.None.class ? test.expected() : null);
}

View File

@@ -2,9 +2,7 @@
* Support classes for integrating the <em>Spring TestContext Framework</em>
* with JUnit 4.12 or higher.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.junit4;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,9 +1,7 @@
/**
* Custom JUnit 4 {@code Rules} used in the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.junit4.rules;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,11 +19,11 @@ package org.springframework.test.context.junit4.statements;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
import org.junit.AssumptionViolatedException;
import org.junit.runners.model.Statement;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.annotation.ProfileValueUtils;
import org.springframework.util.Assert;
@@ -46,8 +46,7 @@ public class ProfileValueChecker extends Statement {
private final Class<?> testClass;
@Nullable
private final Method testMethod;
private final @Nullable Method testMethod;
/**

View File

@@ -1,9 +1,7 @@
/**
* Custom JUnit 4 {@code Statements} used in the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.junit4.statements;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -22,10 +22,10 @@ import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.core.Conventions;
import org.springframework.lang.Nullable;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.util.ReflectionUtils;
@@ -68,8 +68,7 @@ class MicrometerObservationRegistryTestExecutionListener extends AbstractTestExe
static final String OBSERVATION_THREAD_LOCAL_ACCESSOR_CLASS_NAME =
"io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor";
@Nullable
private static final String ERROR_MESSAGE;
private static final @Nullable String ERROR_MESSAGE;
static {
// Trigger eager resolution of Micrometer Observation types to ensure that

View File

@@ -1,9 +1,7 @@
/**
* Observation support classes for the <em>Spring TestContext Framework</em>.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context.observation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -11,9 +11,7 @@
* and caching, dependency injection of test fixtures, and transactional test
* management with default rollback semantics.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.test.context;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -20,10 +20,10 @@ import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;

View File

@@ -26,11 +26,11 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.Nullable;
import org.springframework.test.context.BootstrapContext;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.ContextConfiguration;
@@ -79,8 +79,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
private final Log logger = LogFactory.getLog(getClass());
@Nullable
private BootstrapContext bootstrapContext;
private @Nullable BootstrapContext bootstrapContext;
@Override
@@ -533,8 +532,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
* @throws IllegalArgumentException if supplied configuration attributes are
* {@code null} or <em>empty</em>
*/
@Nullable
protected Class<? extends ContextLoader> resolveExplicitContextLoaderClass(
protected @Nullable Class<? extends ContextLoader> resolveExplicitContextLoaderClass(
List<ContextConfigurationAttributes> configAttributesList) {
Assert.notNull(configAttributesList, "ContextConfigurationAttributes list must not be null");

View File

@@ -22,10 +22,10 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
import org.springframework.test.context.SmartContextLoader;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

View File

@@ -21,12 +21,13 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.DefaultToStringStyler;
import org.springframework.core.style.SimpleValueStyler;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.MergedContextConfiguration;
@@ -56,14 +57,11 @@ public class DefaultTestContext implements TestContext {
private final Class<?> testClass;
@Nullable
private volatile Object testInstance;
private volatile @Nullable Object testInstance;
@Nullable
private volatile Method testMethod;
private volatile @Nullable Method testMethod;
@Nullable
private volatile Throwable testException;
private volatile @Nullable Throwable testException;
private volatile MethodInvoker methodInvoker = MethodInvoker.DEFAULT_INVOKER;
@@ -174,8 +172,7 @@ public class DefaultTestContext implements TestContext {
}
@Override
@Nullable
public final Throwable getTestException() {
public final @Nullable Throwable getTestException() {
return this.testException;
}
@@ -211,8 +208,7 @@ public class DefaultTestContext implements TestContext {
}
@Override
@Nullable
public Object getAttribute(String name) {
public @Nullable Object getAttribute(String name) {
Assert.notNull(name, "Name must not be null");
return this.attributes.get(name);
}
@@ -229,8 +225,7 @@ public class DefaultTestContext implements TestContext {
}
@Override
@Nullable
public Object removeAttribute(String name) {
public @Nullable Object removeAttribute(String name) {
Assert.notNull(name, "Name must not be null");
return this.attributes.remove(name);
}

View File

@@ -20,13 +20,14 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextCustomizer;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.MergedContextConfiguration;

View File

@@ -22,9 +22,10 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.ContextCustomizerFactory;
import org.springframework.test.context.DynamicPropertySource;
@@ -45,8 +46,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFactory {
@Override
@Nullable
public DynamicPropertiesContextCustomizer createContextCustomizer(Class<?> testClass,
public @Nullable DynamicPropertiesContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) {
Set<Method> methods = new LinkedHashSet<>();

View File

@@ -18,6 +18,7 @@ package org.springframework.test.context.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactoryInitializer;
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -25,7 +26,6 @@ import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.lang.Nullable;
import org.springframework.test.context.DynamicPropertyRegistrar;
import org.springframework.test.context.DynamicPropertyRegistry;
@@ -49,8 +49,7 @@ public class DynamicPropertyRegistrarBeanInitializer implements BeanFactoryIniti
"org.springframework.test.context.support.internalDynamicPropertyRegistrarBeanInitializer";
@Nullable
private ConfigurableEnvironment environment;
private @Nullable ConfigurableEnvironment environment;
@Override

Some files were not shown because too many files have changed in this diff Show More