Specify generic type nullness in spring-webflux
See gh-34140
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -63,11 +63,13 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128
|
||||||
public @Nullable Validator getValidator() {
|
public @Nullable Validator getValidator() {
|
||||||
return createSingleBean(WebFluxConfigurer::getValidator, Validator.class);
|
return createSingleBean(WebFluxConfigurer::getValidator, Validator.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128
|
||||||
public @Nullable MessageCodesResolver getMessageCodesResolver() {
|
public @Nullable MessageCodesResolver getMessageCodesResolver() {
|
||||||
return createSingleBean(WebFluxConfigurer::getMessageCodesResolver, MessageCodesResolver.class);
|
return createSingleBean(WebFluxConfigurer::getMessageCodesResolver, MessageCodesResolver.class);
|
||||||
}
|
}
|
||||||
@@ -115,11 +117,12 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128
|
||||||
public @Nullable WebSocketService getWebSocketService() {
|
public @Nullable WebSocketService getWebSocketService() {
|
||||||
return createSingleBean(WebFluxConfigurer::getWebSocketService, WebSocketService.class);
|
return createSingleBean(WebFluxConfigurer::getWebSocketService, WebSocketService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> @Nullable T createSingleBean(Function<WebFluxConfigurer, T> factory, Class<T> beanType) {
|
private <T> @Nullable T createSingleBean(Function<WebFluxConfigurer, @Nullable T> factory, Class<T> beanType) {
|
||||||
List<T> result = this.delegates.stream().map(factory).filter(Objects::nonNull).toList();
|
List<T> result = this.delegates.stream().map(factory).filter(Objects::nonNull).toList();
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -232,7 +232,8 @@ class DefaultClientResponse implements ClientResponse {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Function<ResolvableType, ?> initDecodeFunction(byte[] body, @Nullable MediaType contentType) {
|
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
|
||||||
|
private Function<ResolvableType, ? extends @Nullable Object> initDecodeFunction(byte[] body, @Nullable MediaType contentType) {
|
||||||
return targetType -> {
|
return targetType -> {
|
||||||
if (ObjectUtils.isEmpty(body)) {
|
if (ObjectUtils.isEmpty(body)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -79,12 +79,12 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
|
|||||||
/**
|
/**
|
||||||
* Return the underlying conditions, possibly empty but never {@code null}.
|
* Return the underlying conditions, possibly empty but never {@code null}.
|
||||||
*/
|
*/
|
||||||
public List<RequestCondition<?>> getConditions() {
|
public List<@Nullable RequestCondition<?>> getConditions() {
|
||||||
return unwrap();
|
return unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<RequestCondition<?>> unwrap() {
|
private List<@Nullable RequestCondition<?>> unwrap() {
|
||||||
List<RequestCondition<?>> result = new ArrayList<>();
|
List<@Nullable RequestCondition<?>> result = new ArrayList<>();
|
||||||
for (RequestConditionHolder holder : this.requestConditions) {
|
for (RequestConditionHolder holder : this.requestConditions) {
|
||||||
result.add(holder.getCondition());
|
result.add(holder.getCondition());
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,8 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<?> getContent() {
|
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
|
||||||
|
protected Collection<? extends @Nullable Object> getContent() {
|
||||||
return (!isEmpty() ? getConditions() : Collections.emptyList());
|
return (!isEmpty() ? getConditions() : Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,10 +151,11 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
|
|||||||
}
|
}
|
||||||
RequestConditionHolder[] matchingConditions = new RequestConditionHolder[getLength()];
|
RequestConditionHolder[] matchingConditions = new RequestConditionHolder[getLength()];
|
||||||
for (int i = 0; i < getLength(); i++) {
|
for (int i = 0; i < getLength(); i++) {
|
||||||
matchingConditions[i] = this.requestConditions[i].getMatchingCondition(exchange);
|
RequestConditionHolder matchingCondition = this.requestConditions[i].getMatchingCondition(exchange);
|
||||||
if (matchingConditions[i] == null) {
|
if (matchingCondition == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
matchingConditions[i] = matchingCondition;
|
||||||
}
|
}
|
||||||
return new CompositeRequestCondition(matchingConditions);
|
return new CompositeRequestCondition(matchingConditions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -314,7 +314,7 @@ public class RequestMappingHandlerAdapter
|
|||||||
Throwable cause = exToExpose.getCause();
|
Throwable cause = exToExpose.getCause();
|
||||||
exToExpose = (cause != exToExpose ? cause : null);
|
exToExpose = (cause != exToExpose ? cause : null);
|
||||||
}
|
}
|
||||||
Object[] arguments = new Object[exceptions.size() + 1];
|
@Nullable Object[] arguments = new Object[exceptions.size() + 1];
|
||||||
exceptions.toArray(arguments); // efficient arraycopy call in ArrayList
|
exceptions.toArray(arguments); // efficient arraycopy call in ArrayList
|
||||||
arguments[arguments.length - 1] = handlerMethod;
|
arguments[arguments.length - 1] = handlerMethod;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -306,12 +306,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
|||||||
* Resolve placeholder values in the given array of patterns.
|
* Resolve placeholder values in the given array of patterns.
|
||||||
* @return a new array with updated patterns
|
* @return a new array with updated patterns
|
||||||
*/
|
*/
|
||||||
protected String[] resolveEmbeddedValuesInPatterns(String[] patterns) {
|
protected @Nullable String[] resolveEmbeddedValuesInPatterns(String[] patterns) {
|
||||||
if (this.embeddedValueResolver == null) {
|
if (this.embeddedValueResolver == null) {
|
||||||
return patterns;
|
return patterns;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String[] resolvedPatterns = new String[patterns.length];
|
@Nullable String[] resolvedPatterns = new String[patterns.length];
|
||||||
for (int i = 0; i < patterns.length; i++) {
|
for (int i = 0; i < patterns.length; i++) {
|
||||||
resolvedPatterns[i] = this.embeddedValueResolver.resolveStringValue(patterns[i]);
|
resolvedPatterns[i] = this.embeddedValueResolver.resolveStringValue(patterns[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.result.view;
|
|||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ public class BindStatus {
|
|||||||
|
|
||||||
private final @Nullable Errors errors;
|
private final @Nullable Errors errors;
|
||||||
|
|
||||||
private final String[] errorCodes;
|
private final @Nullable String[] errorCodes;
|
||||||
|
|
||||||
private String @Nullable [] errorMessages;
|
private String @Nullable [] errorMessages;
|
||||||
|
|
||||||
@@ -162,8 +163,8 @@ public class BindStatus {
|
|||||||
/**
|
/**
|
||||||
* Extract the error codes from the ObjectError list.
|
* Extract the error codes from the ObjectError list.
|
||||||
*/
|
*/
|
||||||
private static String[] initErrorCodes(List<? extends ObjectError> objectErrors) {
|
private static @Nullable String[] initErrorCodes(List<? extends ObjectError> objectErrors) {
|
||||||
String[] errorCodes = new String[objectErrors.size()];
|
@Nullable String[] errorCodes = new String[objectErrors.size()];
|
||||||
for (int i = 0; i < objectErrors.size(); i++) {
|
for (int i = 0; i < objectErrors.size(); i++) {
|
||||||
ObjectError error = objectErrors.get(i);
|
ObjectError error = objectErrors.get(i);
|
||||||
errorCodes[i] = error.getCode();
|
errorCodes[i] = error.getCode();
|
||||||
@@ -247,7 +248,7 @@ public class BindStatus {
|
|||||||
* Return the error codes for the field or object, if any.
|
* Return the error codes for the field or object, if any.
|
||||||
* Returns an empty array instead of null if none.
|
* Returns an empty array instead of null if none.
|
||||||
*/
|
*/
|
||||||
public String[] getErrorCodes() {
|
public @Nullable String[] getErrorCodes() {
|
||||||
return this.errorCodes;
|
return this.errorCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +256,9 @@ public class BindStatus {
|
|||||||
* Return the first error codes for the field or object, if any.
|
* Return the first error codes for the field or object, if any.
|
||||||
*/
|
*/
|
||||||
public String getErrorCode() {
|
public String getErrorCode() {
|
||||||
return (!ObjectUtils.isEmpty(this.errorCodes) ? this.errorCodes[0] : "");
|
return (!ObjectUtils.isEmpty(this.errorCodes) ? Objects.requireNonNull(this.errorCodes[0],
|
||||||
|
|
||||||
|
"Error code must not be null") : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user