Missing @Nullable annotations in WebFlux, in particular around locale resolution
Issue: SPR-15036 Issue: SPR-15540
This commit is contained in:
@@ -112,11 +112,13 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
mapping.setCorsConfigurations(getCorsConfigurations());
|
||||
|
||||
PathMatchConfigurer configurer = getPathMatchConfigurer();
|
||||
if (configurer.isUseTrailingSlashMatch() != null) {
|
||||
mapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch());
|
||||
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
|
||||
Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
|
||||
if (useTrailingSlashMatch != null) {
|
||||
mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
|
||||
}
|
||||
if (configurer.isUseCaseSensitiveMatch() != null) {
|
||||
mapping.setUseCaseSensitiveMatch(configurer.isUseCaseSensitiveMatch());
|
||||
if (useCaseSensitiveMatch != null) {
|
||||
mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
@@ -209,11 +211,13 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
|
||||
if (handlerMapping != null) {
|
||||
PathMatchConfigurer configurer = getPathMatchConfigurer();
|
||||
if (configurer.isUseTrailingSlashMatch() != null) {
|
||||
handlerMapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch());
|
||||
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
|
||||
Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
|
||||
if (useTrailingSlashMatch != null) {
|
||||
handlerMapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
|
||||
}
|
||||
if (configurer.isUseCaseSensitiveMatch() != null) {
|
||||
handlerMapping.setUseCaseSensitiveMatch(configurer.isUseCaseSensitiveMatch());
|
||||
if (useCaseSensitiveMatch != null) {
|
||||
handlerMapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.stream.Stream;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -155,7 +156,7 @@ class DefaultRenderingResponseBuilder implements RenderingResponse.Builder {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
writeStatusAndHeaders(response);
|
||||
MediaType contentType = exchange.getResponse().getHeaders().getContentType();
|
||||
Locale locale = exchange.getLocaleContext().getLocale();
|
||||
Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext());
|
||||
Stream<ViewResolver> viewResolverStream = context.viewResolvers().stream();
|
||||
|
||||
return Flux.fromStream(viewResolverStream)
|
||||
|
||||
@@ -22,8 +22,10 @@ import org.springframework.web.util.pattern.PathPattern;
|
||||
|
||||
/**
|
||||
* Result of matching an request lookup path against {@link PathPattern} instances.
|
||||
* <p>Each result optionnally associates the matching {@link PathPattern}
|
||||
*
|
||||
* <p>Each result optionally associates the matching {@link PathPattern}
|
||||
* with a request handler of type {@code T}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 5.0
|
||||
* @see PathPatternRegistry
|
||||
@@ -34,17 +36,19 @@ public class PathMatchResult<T> {
|
||||
|
||||
private final T handler;
|
||||
|
||||
public PathMatchResult(PathPattern pattern, T handler) {
|
||||
Assert.notNull(pattern, "PathPattern should not be null");
|
||||
|
||||
public PathMatchResult(PathPattern pattern, @Nullable T handler) {
|
||||
Assert.notNull(pattern, "PathPattern must not be null");
|
||||
this.pattern = pattern;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the {@link PathPattern} that matched the incoming request.
|
||||
*/
|
||||
public PathPattern getPattern() {
|
||||
return pattern;
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +56,7 @@ public class PathMatchResult<T> {
|
||||
*/
|
||||
@Nullable
|
||||
public T getHandler() {
|
||||
return handler;
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.pattern.PathPattern;
|
||||
import org.springframework.web.util.pattern.PathPatternComparator;
|
||||
@@ -55,7 +56,6 @@ public class PathPatternRegistry<T> {
|
||||
/**
|
||||
* Create a new {@code PathPatternRegistry} using
|
||||
* the provided instance of {@link PathPatternParser}.
|
||||
*
|
||||
* @param patternParser the {@link PathPatternParser} to use
|
||||
*/
|
||||
public PathPatternRegistry(PathPatternParser patternParser) {
|
||||
@@ -66,7 +66,6 @@ public class PathPatternRegistry<T> {
|
||||
* Create a new {@code PathPatternRegistry} using
|
||||
* the provided instance of {@link PathPatternParser}
|
||||
* and the given map of {@link PathPattern}.
|
||||
*
|
||||
* @param patternParser the {@link PathPatternParser} to use
|
||||
* @param patternsMap the map of {@link PathPattern} to use
|
||||
*/
|
||||
@@ -75,6 +74,7 @@ public class PathPatternRegistry<T> {
|
||||
this.patternsMap = new HashMap<>(patternsMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a (read-only) map of all patterns and associated values.
|
||||
*/
|
||||
@@ -84,7 +84,6 @@ public class PathPatternRegistry<T> {
|
||||
|
||||
/**
|
||||
* Return a {@code SortedSet} of {@code PathPattern}s matching the given {@code lookupPath}.
|
||||
*
|
||||
* <p>The returned set sorted with the most specific
|
||||
* patterns first, according to the given {@code lookupPath}.
|
||||
* @param lookupPath the URL lookup path to be matched against
|
||||
@@ -99,7 +98,6 @@ public class PathPatternRegistry<T> {
|
||||
|
||||
/**
|
||||
* Return, if any, the most specific {@code PathPattern} matching the given {@code lookupPath}.
|
||||
*
|
||||
* @param lookupPath the URL lookup path to be matched against
|
||||
*/
|
||||
public Optional<PathMatchResult<T>> findFirstMatch(String lookupPath) {
|
||||
@@ -120,7 +118,7 @@ public class PathPatternRegistry<T> {
|
||||
/**
|
||||
* Parse the given {@code rawPattern} and adds it to this registry.
|
||||
* @param rawPattern raw path pattern to parse and register
|
||||
* @param handler
|
||||
* @param handler the associated handler object
|
||||
*/
|
||||
public void register(String rawPattern, T handler) {
|
||||
String fixedPattern = prependLeadingSlash(rawPattern);
|
||||
@@ -137,6 +135,7 @@ public class PathPatternRegistry<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class PathMatchResultComparator<T> implements Comparator<PathMatchResult<T>> {
|
||||
|
||||
private final String path;
|
||||
@@ -146,7 +145,7 @@ public class PathPatternRegistry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(PathMatchResult<T> o1, PathMatchResult<T> o2) {
|
||||
public int compare(@Nullable PathMatchResult<T> o1, @Nullable PathMatchResult<T> o2) {
|
||||
// Nulls get sorted to the end
|
||||
if (o1 == null) {
|
||||
return (o2 == null ? 0 : +1);
|
||||
@@ -171,7 +170,6 @@ public class PathPatternRegistry<T> {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.reactive.handler.PathMatchResult;
|
||||
import org.springframework.web.reactive.handler.PathPatternRegistry;
|
||||
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.reactive.handler.PathMatchResult;
|
||||
import org.springframework.web.util.pattern.PathPattern;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
import org.springframework.web.reactive.handler.PathPatternRegistry;
|
||||
|
||||
/**
|
||||
* A central component to use to obtain the public URL path that clients should
|
||||
@@ -205,6 +205,9 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
logger.trace("Invoking ResourceResolverChain for URL pattern \"" + result.getPattern() + "\"");
|
||||
}
|
||||
ResourceWebHandler handler = result.getHandler();
|
||||
if (handler == null) {
|
||||
throw new IllegalStateException("No handler for URL pattern \"" + result.getPattern() + "\"");
|
||||
}
|
||||
ResourceResolverChain chain = new DefaultResourceResolverChain(handler.getResourceResolvers());
|
||||
return chain.resolveUrlPath(pathWithinMapping, handler.getLocations())
|
||||
.map(resolvedPath -> {
|
||||
|
||||
@@ -29,6 +29,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -200,8 +201,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport
|
||||
Mono<List<View>> viewsMono;
|
||||
Model model = result.getModel();
|
||||
MethodParameter parameter = result.getReturnTypeSource();
|
||||
|
||||
Locale locale = exchange.getLocaleContext().getLocale();
|
||||
Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext());
|
||||
|
||||
Class<?> clazz = valueType.getRawClass();
|
||||
if (clazz == null) {
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -188,8 +189,7 @@ public class FreeMarkerView extends AbstractUrlBasedView {
|
||||
logger.debug("Rendering FreeMarker template [" + getUrl() + "].");
|
||||
}
|
||||
|
||||
Locale locale = exchange.getLocaleContext().getLocale();
|
||||
|
||||
Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext());
|
||||
DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer();
|
||||
try {
|
||||
Charset charset = getCharset(contentType);
|
||||
|
||||
Reference in New Issue
Block a user