Perform NullAway build-time checks in spring-web
Also in spring-websocket. See gh-32475
This commit is contained in:
parent
2b1eb488fc
commit
e52ee01ec8
|
@ -118,7 +118,7 @@ tasks.withType(JavaCompile).configureEach {
|
||||||
disableAllChecks = true
|
disableAllChecks = true
|
||||||
option("NullAway:CustomContractAnnotations", "org.springframework.lang.Contract")
|
option("NullAway:CustomContractAnnotations", "org.springframework.lang.Contract")
|
||||||
option("NullAway:AnnotatedPackages", "org.springframework.core,org.springframework.expression," +
|
option("NullAway:AnnotatedPackages", "org.springframework.core,org.springframework.expression," +
|
||||||
"org.springframework.web.reactive,org.springframework.web.servlet")
|
"org.springframework.web")
|
||||||
option("NullAway:UnannotatedSubPackages", "org.springframework.instrument,org.springframework.context.index," +
|
option("NullAway:UnannotatedSubPackages", "org.springframework.instrument,org.springframework.context.index," +
|
||||||
"org.springframework.asm,org.springframework.cglib,org.springframework.objenesis," +
|
"org.springframework.asm,org.springframework.cglib,org.springframework.objenesis," +
|
||||||
"org.springframework.javapoet,org.springframework.aot.nativex.substitution")
|
"org.springframework.javapoet,org.springframework.aot.nativex.substitution")
|
||||||
|
|
|
@ -62,6 +62,7 @@ public abstract class CollectionUtils {
|
||||||
* @param collection the Collection to check
|
* @param collection the Collection to check
|
||||||
* @return whether the given Collection is empty
|
* @return whether the given Collection is empty
|
||||||
*/
|
*/
|
||||||
|
@Contract("null -> true")
|
||||||
public static boolean isEmpty(@Nullable Collection<?> collection) {
|
public static boolean isEmpty(@Nullable Collection<?> collection) {
|
||||||
return (collection == null || collection.isEmpty());
|
return (collection == null || collection.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ public abstract class ObjectUtils {
|
||||||
* either an Object array or a primitive array.
|
* either an Object array or a primitive array.
|
||||||
* @param obj the object to check
|
* @param obj the object to check
|
||||||
*/
|
*/
|
||||||
|
@Contract("null -> false")
|
||||||
public static boolean isArray(@Nullable Object obj) {
|
public static boolean isArray(@Nullable Object obj) {
|
||||||
return (obj != null && obj.getClass().isArray());
|
return (obj != null && obj.getClass().isArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,6 +201,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||||
* {@link RestClientResponseException#setBodyConvertFunction(Function)}.
|
* {@link RestClientResponseException#setBodyConvertFunction(Function)}.
|
||||||
* @since 6.0
|
* @since 6.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
protected Function<ResolvableType, ?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) {
|
protected Function<ResolvableType, ?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) {
|
||||||
Assert.state(!CollectionUtils.isEmpty(this.messageConverters), "Expected message converters");
|
Assert.state(!CollectionUtils.isEmpty(this.messageConverters), "Expected message converters");
|
||||||
return resolvableType -> {
|
return resolvableType -> {
|
||||||
|
|
|
@ -522,6 +522,7 @@ final class DefaultRestClient implements RestClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
private ClientHttpRequest createRequest(URI uri) throws IOException {
|
private ClientHttpRequest createRequest(URI uri) throws IOException {
|
||||||
ClientHttpRequestFactory factory;
|
ClientHttpRequestFactory factory;
|
||||||
if (DefaultRestClient.this.interceptors != null) {
|
if (DefaultRestClient.this.interceptors != null) {
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.springframework.web.context.request;
|
||||||
|
|
||||||
import io.micrometer.context.ThreadLocalAccessor;
|
import io.micrometer.context.ThreadLocalAccessor;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapt {@link RequestContextHolder} to the {@link ThreadLocalAccessor} contract
|
* Adapt {@link RequestContextHolder} to the {@link ThreadLocalAccessor} contract
|
||||||
* to assist the Micrometer Context Propagation library with
|
* to assist the Micrometer Context Propagation library with
|
||||||
|
@ -40,6 +42,7 @@ public class RequestAttributesThreadLocalAccessor implements ThreadLocalAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public RequestAttributes getValue() {
|
public RequestAttributes getValue() {
|
||||||
return RequestContextHolder.getRequestAttributes();
|
return RequestContextHolder.getRequestAttributes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||||
* @param previousRequest the existing request from the last dispatch
|
* @param previousRequest the existing request from the last dispatch
|
||||||
* @since 5.3.33
|
* @since 5.3.33
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response,
|
StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response,
|
||||||
@Nullable StandardServletAsyncWebRequest previousRequest) {
|
@Nullable StandardServletAsyncWebRequest previousRequest) {
|
||||||
|
|
||||||
|
@ -243,6 +244,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public ServletOutputStream getOutputStream() throws IOException {
|
public ServletOutputStream getOutputStream() throws IOException {
|
||||||
int level = obtainLockAndCheckState();
|
int level = obtainLockAndCheckState();
|
||||||
try {
|
try {
|
||||||
|
@ -262,6 +264,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public PrintWriter getWriter() throws IOException {
|
public PrintWriter getWriter() throws IOException {
|
||||||
int level = obtainLockAndCheckState();
|
int level = obtainLockAndCheckState();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -287,6 +287,7 @@ public final class WebAsyncManager {
|
||||||
* via {@link #getConcurrentResultContext()}
|
* via {@link #getConcurrentResultContext()}
|
||||||
* @throws Exception if concurrent processing failed to start
|
* @throws Exception if concurrent processing failed to start
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object... processingContext)
|
public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object... processingContext)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
|
@ -408,6 +409,7 @@ public final class WebAsyncManager {
|
||||||
* @see #getConcurrentResult()
|
* @see #getConcurrentResult()
|
||||||
* @see #getConcurrentResultContext()
|
* @see #getConcurrentResultContext()
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public void startDeferredResultProcessing(
|
public void startDeferredResultProcessing(
|
||||||
final DeferredResult<?> deferredResult, Object... processingContext) throws Exception {
|
final DeferredResult<?> deferredResult, Object... processingContext) throws Exception {
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
|
||||||
* @see ServletContextResource
|
* @see ServletContextResource
|
||||||
* @see jakarta.servlet.ServletContext#getResourcePaths
|
* @see jakarta.servlet.ServletContext#getResourcePaths
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
protected void doRetrieveMatchingServletContextResources(
|
protected void doRetrieveMatchingServletContextResources(
|
||||||
ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
|
ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
|
@ -171,6 +171,7 @@ public class CorsConfiguration {
|
||||||
/**
|
/**
|
||||||
* Variant of {@link #setAllowedOrigins} for adding one origin at a time.
|
* Variant of {@link #setAllowedOrigins} for adding one origin at a time.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public void addAllowedOrigin(@Nullable String origin) {
|
public void addAllowedOrigin(@Nullable String origin) {
|
||||||
if (origin == null) {
|
if (origin == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -244,6 +245,7 @@ public class CorsConfiguration {
|
||||||
* Variant of {@link #setAllowedOriginPatterns} for adding one origin at a time.
|
* Variant of {@link #setAllowedOriginPatterns} for adding one origin at a time.
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public void addAllowedOriginPattern(@Nullable String originPattern) {
|
public void addAllowedOriginPattern(@Nullable String originPattern) {
|
||||||
if (originPattern == null) {
|
if (originPattern == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -342,7 +342,7 @@ public class HandlerMethod extends AnnotatedMethod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object other) {
|
||||||
return (this == other || (super.equals(other) && this.bean.equals(((HandlerMethod) other).bean)));
|
return (this == other || (super.equals(other) && other instanceof HandlerMethod otherMethod && this.bean.equals(otherMethod.bean)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -136,6 +136,7 @@ public abstract class AbstractMultipartHttpServletRequest extends HttpServletReq
|
||||||
* lazily initializing it if necessary.
|
* lazily initializing it if necessary.
|
||||||
* @see #initializeMultipart()
|
* @see #initializeMultipart()
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
protected MultiValueMap<String, MultipartFile> getMultipartFiles() {
|
protected MultiValueMap<String, MultipartFile> getMultipartFiles() {
|
||||||
if (this.multipartFiles == null) {
|
if (this.multipartFiles == null) {
|
||||||
initializeMultipart();
|
initializeMultipart();
|
||||||
|
|
|
@ -137,6 +137,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public Enumeration<String> getParameterNames() {
|
public Enumeration<String> getParameterNames() {
|
||||||
if (this.multipartParameterNames == null) {
|
if (this.multipartParameterNames == null) {
|
||||||
initializeMultipart();
|
initializeMultipart();
|
||||||
|
@ -157,6 +158,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public Map<String, String[]> getParameterMap() {
|
public Map<String, String[]> getParameterMap() {
|
||||||
if (this.multipartParameterNames == null) {
|
if (this.multipartParameterNames == null) {
|
||||||
initializeMultipart();
|
initializeMultipart();
|
||||||
|
|
|
@ -152,6 +152,7 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
||||||
/**
|
/**
|
||||||
* Return the configured {@link ServerCodecConfigurer}.
|
* Return the configured {@link ServerCodecConfigurer}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public ServerCodecConfigurer getCodecConfigurer() {
|
public ServerCodecConfigurer getCodecConfigurer() {
|
||||||
if (this.codecConfigurer == null) {
|
if (this.codecConfigurer == null) {
|
||||||
setCodecConfigurer(ServerCodecConfigurer.create());
|
setCodecConfigurer(ServerCodecConfigurer.create());
|
||||||
|
|
|
@ -189,6 +189,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return this.id.get();
|
return this.id.get();
|
||||||
}
|
}
|
||||||
|
@ -224,6 +225,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public boolean isStarted() {
|
public boolean isStarted() {
|
||||||
return this.state.get().equals(State.STARTED) || !getAttributes().isEmpty();
|
return this.state.get().equals(State.STARTED) || !getAttributes().isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -252,6 +254,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
public Mono<Void> save() {
|
public Mono<Void> save() {
|
||||||
|
|
||||||
checkMaxSessionsLimit();
|
checkMaxSessionsLimit();
|
||||||
|
@ -289,6 +292,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||||
return isExpired(clock.instant());
|
return isExpired(clock.instant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
private boolean isExpired(Instant now) {
|
private boolean isExpired(Instant now) {
|
||||||
if (this.state.get().equals(State.EXPIRED)) {
|
if (this.state.get().equals(State.EXPIRED)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -223,6 +223,7 @@ final class HttpServiceMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@SuppressWarnings("NullAway")
|
||||||
private static String initUrl(
|
private static String initUrl(
|
||||||
@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation,
|
@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation,
|
||||||
@Nullable StringValueResolver embeddedValueResolver) {
|
@Nullable StringValueResolver embeddedValueResolver) {
|
||||||
|
|
|
@ -251,7 +251,7 @@ public final class HttpServiceProxyFactory {
|
||||||
this.exchangeAdapter, initArgumentResolvers(), this.embeddedValueResolver);
|
this.exchangeAdapter, initArgumentResolvers(), this.embeddedValueResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings({"DataFlowIssue", "NullAway"})
|
||||||
private List<HttpServiceArgumentResolver> initArgumentResolvers() {
|
private List<HttpServiceArgumentResolver> initArgumentResolvers() {
|
||||||
|
|
||||||
// Custom
|
// Custom
|
||||||
|
|
Loading…
Reference in New Issue