Missing @Nullable annotations in WebFlux, in particular around locale resolution
Issue: SPR-15036 Issue: SPR-15540
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.server.reactive;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
@@ -21,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -93,7 +95,7 @@ class DefaultPathSegmentContainer implements PathSegmentContainer {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
@@ -224,12 +226,10 @@ class DefaultPathSegmentContainer implements PathSegmentContainer {
|
||||
|
||||
private final MultiValueMap<String, String> parameters;
|
||||
|
||||
|
||||
DefaultPathSegment(String value, String valueDecoded, String semicolonContent,
|
||||
MultiValueMap<String, String> params) {
|
||||
|
||||
Assert.isTrue(!value.contains("/"), "Invalid path segment value: " + value);
|
||||
|
||||
this.value = value;
|
||||
this.valueDecoded = valueDecoded;
|
||||
this.valueCharsDecoded = valueDecoded.toCharArray();
|
||||
@@ -238,7 +238,6 @@ class DefaultPathSegmentContainer implements PathSegmentContainer {
|
||||
this.parameters = CollectionUtils.unmodifiableMultiValueMap(params);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return this.value;
|
||||
@@ -269,9 +268,8 @@ class DefaultPathSegmentContainer implements PathSegmentContainer {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -126,7 +127,7 @@ class DefaultRequestPath implements RequestPath {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver
|
||||
* determined via {@link HttpHeaders#getAcceptLanguageAsLocales()}.
|
||||
* @param locales the supported locales
|
||||
*/
|
||||
public void setSupportedLocales(List<Locale> locales) {
|
||||
public void setSupportedLocales(@Nullable List<Locale> locales) {
|
||||
this.supportedLocales.clear();
|
||||
if (locales != null) {
|
||||
this.supportedLocales.addAll(locales);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,6 @@ public interface LocaleContextResolver {
|
||||
|
||||
/**
|
||||
* Resolve the current locale context via the given exchange.
|
||||
*
|
||||
* <p>The returned context may be a
|
||||
* {@link org.springframework.context.i18n.TimeZoneAwareLocaleContext},
|
||||
* containing a locale with associated time zone information.
|
||||
@@ -44,7 +43,7 @@ public interface LocaleContextResolver {
|
||||
* <p>Custom resolver implementations may also return extra settings in
|
||||
* the returned context, which again can be accessed through downcasting.
|
||||
* @param exchange current server exchange
|
||||
* @return the current locale context (never {@code null}
|
||||
* @return the current locale context (never {@code null})
|
||||
*/
|
||||
LocaleContext resolveLocaleContext(ServerWebExchange exchange);
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.web.util.pattern;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link PathPattern} comparator that takes account of a specified
|
||||
* path and sorts anything that exactly matches it to be first.
|
||||
@@ -34,12 +36,14 @@ public class PathPatternComparator implements Comparator<PathPattern> {
|
||||
|
||||
private final String path;
|
||||
|
||||
|
||||
public PathPatternComparator(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(PathPattern o1, PathPattern o2) {
|
||||
public int compare(@Nullable PathPattern o1, @Nullable PathPattern o2) {
|
||||
// Nulls get sorted to the end
|
||||
if (o1 == null) {
|
||||
return (o2 == null ? 0 : +1);
|
||||
@@ -47,6 +51,7 @@ public class PathPatternComparator implements Comparator<PathPattern> {
|
||||
else if (o2 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// exact matches get sorted first
|
||||
if (o1.getPatternString().equals(path)) {
|
||||
return (o2.getPatternString().equals(path)) ? 0 : -1;
|
||||
@@ -54,6 +59,7 @@ public class PathPatternComparator implements Comparator<PathPattern> {
|
||||
else if (o2.getPatternString().equals(path)) {
|
||||
return +1;
|
||||
}
|
||||
|
||||
// compare pattern specificity
|
||||
int result = o1.compareTo(o2);
|
||||
// if equal specificity, sort using pattern string
|
||||
@@ -63,4 +69,4 @@ public class PathPatternComparator implements Comparator<PathPattern> {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user