Browse Source

Apply "instanceof pattern matching" in spring-webflux

This commit also applies additional clean-up tasks such as the following.

- final fields
- diamond operator (<>) for anonymous inner classes
- multi-catch

This has only been applied to `src/main/java`.
pull/27567/head
Sam Brannen 5 years ago
parent
commit
8135ae6d38
  1. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java
  2. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java
  3. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ChangePathPatternParserVisitor.java
  4. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java
  5. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java
  6. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java
  7. 6
      spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractUrlHandlerMapping.java
  8. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java
  9. 21
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java
  10. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java
  11. 13
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java
  12. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java
  13. 13
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java
  14. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java
  15. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java
  16. 16
      spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java
  17. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java
  18. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java
  19. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketMessage.java
  20. 17
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketHandlerAdapter.java

8
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -66,7 +66,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
}; };
private ExchangeStrategies strategies; private final ExchangeStrategies strategies;
private int statusCode = 200; private int statusCode = 200;
@ -104,8 +104,8 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
this.headers.addAll(other.headers().asHttpHeaders()); this.headers.addAll(other.headers().asHttpHeaders());
} }
this.originalResponse = other; this.originalResponse = other;
this.request = (other instanceof DefaultClientResponse ? this.request = (other instanceof DefaultClientResponse defaultClientResponse ?
((DefaultClientResponse) other).request() : EMPTY_REQUEST); defaultClientResponse.request() : EMPTY_REQUEST);
} }

8
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -116,8 +116,7 @@ public abstract class ExchangeFilterFunctions {
public static ExchangeFilterFunction basicAuthentication() { public static ExchangeFilterFunction basicAuthentication() {
return (request, next) -> { return (request, next) -> {
Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE); Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE);
if (attr instanceof Credentials) { if (attr instanceof Credentials cred) {
Credentials cred = (Credentials) attr;
return next.exchange(ClientRequest.from(request) return next.exchange(ClientRequest.from(request)
.headers(headers -> headers.setBasicAuth(cred.username, cred.password)) .headers(headers -> headers.setBasicAuth(cred.username, cred.password))
.build()); .build());
@ -174,10 +173,9 @@ public abstract class ExchangeFilterFunctions {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof Credentials)) { if (!(other instanceof Credentials otherCred)) {
return false; return false;
} }
Credentials otherCred = (Credentials) other;
return (this.username.equals(otherCred.username) && this.password.equals(otherCred.password)); return (this.username.equals(otherCred.username) && this.password.equals(otherCred.password));
} }

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ChangePathPatternParserVisitor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -70,8 +70,7 @@ class ChangePathPatternParserVisitor implements RouterFunctions.Visitor {
} }
private void changeParser(RequestPredicate predicate) { private void changeParser(RequestPredicate predicate) {
if (predicate instanceof Target) { if (predicate instanceof Target target) {
Target target = (Target) predicate;
target.changeParser(this.parser); target.changeParser(this.parser);
} }
} }

2
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java

@ -195,7 +195,7 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> {
@Override @Override
public Mono<EntityResponse<T>> build() { public Mono<EntityResponse<T>> build() {
return Mono.just(new DefaultEntityResponse<T>( return Mono.just(new DefaultEntityResponse<>(
this.status, this.headers, this.cookies, this.entity, this.inserter, this.hints)); this.status, this.headers, this.cookies, this.entity, this.inserter, this.hints));
} }

4
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -69,7 +69,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
private final List<HttpMessageReader<?>> messageReaders; private final List<HttpMessageReader<?>> messageReaders;
private ServerWebExchange exchange; private final ServerWebExchange exchange;
private String methodName; private String methodName;

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -78,8 +78,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
Assert.notNull(other, "ServerResponse must not be null"); Assert.notNull(other, "ServerResponse must not be null");
this.headers.addAll(other.headers()); this.headers.addAll(other.headers());
this.cookies.addAll(other.cookies()); this.cookies.addAll(other.cookies());
if (other instanceof AbstractServerResponse) { if (other instanceof AbstractServerResponse abstractOther) {
AbstractServerResponse abstractOther = (AbstractServerResponse) other;
this.statusCode = abstractOther.statusCode; this.statusCode = abstractOther.statusCode;
this.hints.putAll(abstractOther.hints); this.hints.putAll(abstractOther.hints);
} }

6
spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractUrlHandlerMapping.java

@ -153,8 +153,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
Object handler = this.handlerMap.get(pattern); Object handler = this.handlerMap.get(pattern);
// Bean name or resolved handler? // Bean name or resolved handler?
if (handler instanceof String) { if (handler instanceof String handlerName) {
String handlerName = (String) handler;
handler = obtainApplicationContext().getBean(handlerName); handler = obtainApplicationContext().getBean(handlerName);
} }
@ -223,8 +222,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
} }
// Eagerly resolve handler if referencing singleton via name. // Eagerly resolve handler if referencing singleton via name.
if (!this.lazyInitHandlers && handler instanceof String) { if (!this.lazyInitHandlers && handler instanceof String handlerName) {
String handlerName = (String) handler;
if (obtainApplicationContext().isSingleton(handlerName)) { if (obtainApplicationContext().isSingleton(handlerName)) {
resolvedHandler = obtainApplicationContext().getBean(handlerName); resolvedHandler = obtainApplicationContext().getBean(handlerName);
} }

5
spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 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.
@ -288,10 +288,9 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof ContentChunkInfo)) { if (!(other instanceof ContentChunkInfo otherCci)) {
return false; return false;
} }
ContentChunkInfo otherCci = (ContentChunkInfo) other;
return (this.start == otherCci.start && this.end == otherCci.end); return (this.start == otherCci.start && this.end == otherCci.end);
} }

21
spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java

@ -42,6 +42,7 @@ import org.springframework.web.util.UriUtils;
* expected to be configured at the end in a chain of resolvers. * expected to be configured at the end in a chain of resolvers.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen
* @since 5.0 * @since 5.0
*/ */
public class PathResourceResolver extends AbstractResourceResolver { public class PathResourceResolver extends AbstractResourceResolver {
@ -119,11 +120,12 @@ public class PathResourceResolver extends AbstractResourceResolver {
return Mono.just(resource); return Mono.just(resource);
} }
else if (logger.isWarnEnabled()) { else if (logger.isWarnEnabled()) {
Resource[] allowedLocations = getAllowedLocations(); Object allowedLocationsText = (getAllowedLocations() != null ? Arrays.asList(getAllowedLocations()) : "[]");
logger.warn("Resource path \"" + resourcePath + "\" was successfully resolved " + logger.warn("""
"but resource \"" + resource.getURL() + "\" is neither under the " + Resource path "%s" was successfully resolved, but resource \
"current location \"" + location.getURL() + "\" nor under any of the " + "%s" is neither under the current location "%s" nor under any \
"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]")); of the allowed locations %s"\
""".formatted(resourcePath, resource.getURL(),location.getURL(), allowedLocationsText));
} }
} }
return Mono.empty(); return Mono.empty();
@ -177,8 +179,8 @@ public class PathResourceResolver extends AbstractResourceResolver {
resourcePath = resource.getURL().toExternalForm(); resourcePath = resource.getURL().toExternalForm();
locationPath = StringUtils.cleanPath(location.getURL().toString()); locationPath = StringUtils.cleanPath(location.getURL().toString());
} }
else if (resource instanceof ClassPathResource) { else if (resource instanceof ClassPathResource classPathResource) {
resourcePath = ((ClassPathResource) resource).getPath(); resourcePath = classPathResource.getPath();
locationPath = StringUtils.cleanPath(((ClassPathResource) location).getPath()); locationPath = StringUtils.cleanPath(((ClassPathResource) location).getPath());
} }
else { else {
@ -203,10 +205,7 @@ public class PathResourceResolver extends AbstractResourceResolver {
return true; return true;
} }
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException | UnsupportedEncodingException ex) {
// May not be possible to decode...
}
catch (UnsupportedEncodingException ex) {
// Should never happen... // Should never happen...
} }
} }

3
spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java

@ -106,8 +106,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
mappings.forEach(mapping -> mappings.forEach(mapping ->
mapping.getHandlerMap().forEach((pattern, handler) -> { mapping.getHandlerMap().forEach((pattern, handler) -> {
if (handler instanceof ResourceWebHandler) { if (handler instanceof ResourceWebHandler resourceHandler) {
ResourceWebHandler resourceHandler = (ResourceWebHandler) handler;
this.handlerMap.put(pattern, resourceHandler); this.handlerMap.put(pattern, resourceHandler);
} }
})); }));

13
spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

@ -354,8 +354,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
return; return;
} }
for (int i = getResourceResolvers().size() - 1; i >= 0; i--) { for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
if (getResourceResolvers().get(i) instanceof PathResourceResolver) { if (getResourceResolvers().get(i) instanceof PathResourceResolver resolver) {
PathResourceResolver resolver = (PathResourceResolver) getResourceResolvers().get(i);
if (ObjectUtils.isEmpty(resolver.getAllowedLocations())) { if (ObjectUtils.isEmpty(resolver.getAllowedLocations())) {
resolver.setAllowedLocations(getLocations().toArray(new Resource[0])); resolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
} }
@ -522,10 +521,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
return true; return true;
} }
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException | UnsupportedEncodingException ex) {
// May not be possible to decode...
}
catch (UnsupportedEncodingException ex) {
// Should never happen... // Should never happen...
} }
} }
@ -609,9 +605,8 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
headers.setContentType(mediaType); headers.setContentType(mediaType);
} }
if (resource instanceof HttpResource) { if (resource instanceof HttpResource httpResource) {
HttpHeaders resourceHeaders = ((HttpResource) resource).getResponseHeaders(); exchange.getResponse().getHeaders().putAll(httpResource.getResponseHeaders());
exchange.getResponse().getHeaders().putAll(resourceHeaders);
} }
} }

8
spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -65,7 +65,7 @@ import org.springframework.web.server.ServerWebExchange;
*/ */
public class VersionResourceResolver extends AbstractResourceResolver { public class VersionResourceResolver extends AbstractResourceResolver {
private AntPathMatcher pathMatcher = new AntPathMatcher(); private final AntPathMatcher pathMatcher = new AntPathMatcher();
/** Map from path pattern -> VersionStrategy. */ /** Map from path pattern -> VersionStrategy. */
private final Map<String, VersionStrategy> versionStrategyMap = new LinkedHashMap<>(); private final Map<String, VersionStrategy> versionStrategyMap = new LinkedHashMap<>();
@ -315,8 +315,8 @@ public class VersionResourceResolver extends AbstractResourceResolver {
@Override @Override
public HttpHeaders getResponseHeaders() { public HttpHeaders getResponseHeaders() {
HttpHeaders headers = (this.original instanceof HttpResource ? HttpHeaders headers = (this.original instanceof HttpResource httpResource ?
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders()); httpResource.getResponseHeaders() : new HttpHeaders());
headers.setETag("W/\"" + this.version + "\""); headers.setETag("W/\"" + this.version + "\"");
return headers; return headers;
} }

13
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java

@ -200,8 +200,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
* @param handler the bean name of a handler or a handler instance * @param handler the bean name of a handler or a handler instance
*/ */
protected void detectHandlerMethods(final Object handler) { protected void detectHandlerMethods(final Object handler) {
Class<?> handlerType = (handler instanceof String ? Class<?> handlerType = (handler instanceof String beanName ?
obtainApplicationContext().getType((String) handler) : handler.getClass()); obtainApplicationContext().getType(beanName) : handler.getClass());
if (handlerType != null) { if (handlerType != null) {
final Class<?> userType = ClassUtils.getUserClass(handlerType); final Class<?> userType = ClassUtils.getUserClass(handlerType);
@ -258,8 +258,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
* @return the created HandlerMethod * @return the created HandlerMethod
*/ */
protected HandlerMethod createHandlerMethod(Object handler, Method method) { protected HandlerMethod createHandlerMethod(Object handler, Method method) {
if (handler instanceof String) { if (handler instanceof String beanName) {
return new HandlerMethod((String) handler, return new HandlerMethod(beanName,
obtainApplicationContext().getAutowireCapableBeanFactory(), obtainApplicationContext().getAutowireCapableBeanFactory(),
obtainApplicationContext(), obtainApplicationContext(),
method); method);
@ -397,14 +397,13 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
@Override @Override
protected boolean hasCorsConfigurationSource(Object handler) { protected boolean hasCorsConfigurationSource(Object handler) {
return super.hasCorsConfigurationSource(handler) || return super.hasCorsConfigurationSource(handler) ||
(handler instanceof HandlerMethod && this.mappingRegistry.getCorsConfiguration((HandlerMethod) handler) != null); (handler instanceof HandlerMethod handlerMethod && this.mappingRegistry.getCorsConfiguration(handlerMethod) != null);
} }
@Override @Override
protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) { protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) {
CorsConfiguration corsConfig = super.getCorsConfiguration(handler, exchange); CorsConfiguration corsConfig = super.getCorsConfiguration(handler, exchange);
if (handler instanceof HandlerMethod) { if (handler instanceof HandlerMethod handlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) { if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) {
return ALLOW_CORS_CONFIG; return ALLOW_CORS_CONFIG;
} }

3
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java

@ -224,8 +224,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
return true; return true;
} }
Type parameterType = returnType.getGenericParameterType(); Type parameterType = returnType.getGenericParameterType();
if (parameterType instanceof ParameterizedType) { if (parameterType instanceof ParameterizedType type) {
ParameterizedType type = (ParameterizedType) parameterType;
if (type.getActualTypeArguments().length == 1) { if (type.getActualTypeArguments().length == 1) {
return Void.class.equals(type.getActualTypeArguments()[0]); return Void.class.equals(type.getActualTypeArguments()[0]);
} }

3
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java

@ -343,10 +343,9 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof RequestMappingInfo)) { if (!(other instanceof RequestMappingInfo otherInfo)) {
return false; return false;
} }
RequestMappingInfo otherInfo = (RequestMappingInfo) other;
return (this.patternsCondition.equals(otherInfo.patternsCondition) && return (this.patternsCondition.equals(otherInfo.patternsCondition) &&
this.methodsCondition.equals(otherInfo.methodsCondition) && this.methodsCondition.equals(otherInfo.methodsCondition) &&
this.paramsCondition.equals(otherInfo.paramsCondition) && this.paramsCondition.equals(otherInfo.paramsCondition) &&

16
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 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.
@ -72,7 +72,7 @@ public class RequestContext {
private Map<String, Errors> errorsMap; private Map<String, Errors> errorsMap;
@Nullable @Nullable
private RequestDataValueProcessor dataValueProcessor; private final RequestDataValueProcessor dataValueProcessor;
public RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource) { public RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource) {
@ -92,8 +92,8 @@ public class RequestContext {
LocaleContext localeContext = exchange.getLocaleContext(); LocaleContext localeContext = exchange.getLocaleContext();
Locale locale = localeContext.getLocale(); Locale locale = localeContext.getLocale();
this.locale = (locale != null ? locale : Locale.getDefault()); this.locale = (locale != null ? locale : Locale.getDefault());
TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ? TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext tzaLocaleContext ?
((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null); tzaLocaleContext.getTimeZone() : null);
this.timeZone = (timeZone != null ? timeZone : TimeZone.getDefault()); this.timeZone = (timeZone != null ? timeZone : TimeZone.getDefault());
this.defaultHtmlEscape = null; // TODO this.defaultHtmlEscape = null; // TODO
@ -385,15 +385,15 @@ public class RequestContext {
} }
} }
if (errors instanceof BindException) { if (errors instanceof BindException bindException) {
errors = ((BindException) errors).getBindingResult(); errors = bindException.getBindingResult();
} }
if (htmlEscape && !(errors instanceof EscapedErrors)) { if (htmlEscape && !(errors instanceof EscapedErrors)) {
errors = new EscapedErrors(errors); errors = new EscapedErrors(errors);
} }
else if (!htmlEscape && errors instanceof EscapedErrors) { else if (!htmlEscape && errors instanceof EscapedErrors escapedErrors) {
errors = ((EscapedErrors) errors).getSource(); errors = escapedErrors.getSource();
} }
this.errorsMap.put(name, errors); this.errorsMap.put(name, errors);

4
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2021 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.
@ -40,7 +40,7 @@ public abstract class ViewResolverSupport implements Ordered {
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.parseMediaType("text/html;charset=UTF-8"); public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.parseMediaType("text/html;charset=UTF-8");
private List<MediaType> mediaTypes = new ArrayList<>(4); private final List<MediaType> mediaTypes = new ArrayList<>(4);
private Charset defaultCharset = StandardCharsets.UTF_8; private Charset defaultCharset = StandardCharsets.UTF_8;

5
spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -239,10 +239,9 @@ public final class CloseStatus {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof CloseStatus)) { if (!(other instanceof CloseStatus otherStatus)) {
return false; return false;
} }
CloseStatus otherStatus = (CloseStatus) other;
return (this.code == otherStatus.code && return (this.code == otherStatus.code &&
ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason)); ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason));
} }

5
spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketMessage.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -151,10 +151,9 @@ public class WebSocketMessage {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof WebSocketMessage)) { if (!(other instanceof WebSocketMessage otherMessage)) {
return false; return false;
} }
WebSocketMessage otherMessage = (WebSocketMessage) other;
return (this.type.equals(otherMessage.type) && return (this.type.equals(otherMessage.type) &&
ObjectUtils.nullSafeEquals(this.payload, otherMessage.payload)); ObjectUtils.nullSafeEquals(this.payload, otherMessage.payload));
} }

17
spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketHandlerAdapter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 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.
@ -41,13 +41,14 @@ import org.springframework.web.reactive.socket.WebSocketSession;
* *
* @author Violeta Georgieva * @author Violeta Georgieva
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen
* @since 5.0 * @since 5.0
*/ */
public class StandardWebSocketHandlerAdapter extends Endpoint { public class StandardWebSocketHandlerAdapter extends Endpoint {
private final WebSocketHandler delegateHandler; private final WebSocketHandler delegateHandler;
private Function<Session, StandardWebSocketSession> sessionFactory; private final Function<Session, StandardWebSocketSession> sessionFactory;
@Nullable @Nullable
private StandardWebSocketSession delegateSession; private StandardWebSocketSession delegateSession;
@ -89,16 +90,16 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
private <T> WebSocketMessage toMessage(T message) { private <T> WebSocketMessage toMessage(T message) {
WebSocketSession session = this.delegateSession; WebSocketSession session = this.delegateSession;
Assert.state(session != null, "Cannot create message without a session"); Assert.state(session != null, "Cannot create message without a session");
if (message instanceof String) { if (message instanceof String text) {
byte[] bytes = ((String) message).getBytes(StandardCharsets.UTF_8); byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
return new WebSocketMessage(Type.TEXT, session.bufferFactory().wrap(bytes)); return new WebSocketMessage(Type.TEXT, session.bufferFactory().wrap(bytes));
} }
else if (message instanceof ByteBuffer) { else if (message instanceof ByteBuffer byteBuffer) {
DataBuffer buffer = session.bufferFactory().wrap((ByteBuffer) message); DataBuffer buffer = session.bufferFactory().wrap(byteBuffer);
return new WebSocketMessage(Type.BINARY, buffer); return new WebSocketMessage(Type.BINARY, buffer);
} }
else if (message instanceof PongMessage) { else if (message instanceof PongMessage pongMessage) {
DataBuffer buffer = session.bufferFactory().wrap(((PongMessage) message).getApplicationData()); DataBuffer buffer = session.bufferFactory().wrap(pongMessage.getApplicationData());
return new WebSocketMessage(Type.PONG, buffer); return new WebSocketMessage(Type.PONG, buffer);
} }
else { else {

Loading…
Cancel
Save