Apply additional 'instanceof pattern matching' in spring-web
See gh-29530
This commit is contained in:
@@ -129,17 +129,18 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
|
|||||||
@Override
|
@Override
|
||||||
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
|
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
|
||||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||||
return (handler instanceof AsyncHandlerMethodReturnValueHandler &&
|
return (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler &&
|
||||||
((AsyncHandlerMethodReturnValueHandler) handler).isAsyncReturnValue(returnValue, returnType));
|
asyncHandler.isAsyncReturnValue(returnValue, returnType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
|
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
|
||||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||||
if (handler instanceof AsyncHandlerMethodReturnValueHandler) {
|
if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler) {
|
||||||
return ((AsyncHandlerMethodReturnValueHandler) handler).toCompletableFuture(returnValue, returnType);
|
return asyncHandler.toCompletableFuture(returnValue, returnType);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 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.
|
||||||
@@ -343,8 +343,8 @@ class ChannelSendOperator<T> extends Mono<Void> implements Scannable {
|
|||||||
private void releaseCachedItem() {
|
private void releaseCachedItem() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Object item = this.item;
|
Object item = this.item;
|
||||||
if (item instanceof DataBuffer) {
|
if (item instanceof DataBuffer dataBuffer) {
|
||||||
DataBufferUtils.release((DataBuffer) item);
|
DataBufferUtils.release(dataBuffer);
|
||||||
}
|
}
|
||||||
this.item = null;
|
this.item = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,10 +180,10 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isStreamingMediaType(@Nullable MediaType mediaType) {
|
private boolean isStreamingMediaType(@Nullable MediaType mediaType) {
|
||||||
if (mediaType == null || !(this.encoder instanceof HttpMessageEncoder)) {
|
if (mediaType == null || !(this.encoder instanceof HttpMessageEncoder<?> httpMessageEncoder)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (MediaType streamingMediaType : ((HttpMessageEncoder<?>) this.encoder).getStreamingMediaTypes()) {
|
for (MediaType streamingMediaType : httpMessageEncoder.getStreamingMediaTypes()) {
|
||||||
if (mediaType.isCompatibleWith(streamingMediaType) && matchParameters(mediaType, streamingMediaType)) {
|
if (mediaType.isCompatibleWith(streamingMediaType) && matchParameters(mediaType, streamingMediaType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 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.
|
||||||
@@ -110,8 +110,8 @@ class JettyHeadersAdapter implements MultiValueMap<String, String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
return (value instanceof String &&
|
return (value instanceof String searchString &&
|
||||||
this.headers.stream().anyMatch(field -> field.contains((String) value)));
|
this.headers.stream().anyMatch(field -> field.contains(searchString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -71,13 +71,13 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
|||||||
this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
|
this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters, Log logger) {
|
HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters, Log logger) {
|
||||||
Assert.notNull(responseType, "'responseType' must not be null");
|
Assert.notNull(responseType, "'responseType' must not be null");
|
||||||
Assert.notEmpty(messageConverters, "'messageConverters' must not be empty");
|
Assert.notEmpty(messageConverters, "'messageConverters' must not be empty");
|
||||||
Assert.noNullElements(messageConverters, "'messageConverters' must not contain null elements");
|
Assert.noNullElements(messageConverters, "'messageConverters' must not contain null elements");
|
||||||
this.responseType = responseType;
|
this.responseType = responseType;
|
||||||
this.responseClass = (responseType instanceof Class ? (Class<T>) responseType : null);
|
this.responseClass = (responseType instanceof Class clazz ? clazz : null);
|
||||||
this.messageConverters = messageConverters;
|
this.messageConverters = messageConverters;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2022 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,16 +65,16 @@ public class RequestContextListener implements ServletRequestListener {
|
|||||||
public void requestDestroyed(ServletRequestEvent requestEvent) {
|
public void requestDestroyed(ServletRequestEvent requestEvent) {
|
||||||
ServletRequestAttributes attributes = null;
|
ServletRequestAttributes attributes = null;
|
||||||
Object reqAttr = requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
|
Object reqAttr = requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
|
||||||
if (reqAttr instanceof ServletRequestAttributes) {
|
if (reqAttr instanceof ServletRequestAttributes servletRequestAttributes) {
|
||||||
attributes = (ServletRequestAttributes) reqAttr;
|
attributes = servletRequestAttributes;
|
||||||
}
|
}
|
||||||
RequestAttributes threadAttributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes threadAttributes = RequestContextHolder.getRequestAttributes();
|
||||||
if (threadAttributes != null) {
|
if (threadAttributes != null) {
|
||||||
// We're assumably within the original request thread...
|
// We're assumably within the original request thread...
|
||||||
LocaleContextHolder.resetLocaleContext();
|
LocaleContextHolder.resetLocaleContext();
|
||||||
RequestContextHolder.resetRequestAttributes();
|
RequestContextHolder.resetRequestAttributes();
|
||||||
if (attributes == null && threadAttributes instanceof ServletRequestAttributes) {
|
if (attributes == null && threadAttributes instanceof ServletRequestAttributes servletRequestAttributes) {
|
||||||
attributes = (ServletRequestAttributes) threadAttributes;
|
attributes = servletRequestAttributes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user