Apply additional 'instanceof pattern matching' in spring-web
See gh-29530
This commit is contained in:
parent
50109dd86d
commit
0c878d2d06
|
|
@ -129,17 +129,18 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
|
|||
@Override
|
||||
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
|
||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||
return (handler instanceof AsyncHandlerMethodReturnValueHandler &&
|
||||
((AsyncHandlerMethodReturnValueHandler) handler).isAsyncReturnValue(returnValue, returnType));
|
||||
return (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler &&
|
||||
asyncHandler.isAsyncReturnValue(returnValue, returnType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
|
||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||
if (handler instanceof AsyncHandlerMethodReturnValueHandler) {
|
||||
return ((AsyncHandlerMethodReturnValueHandler) handler).toCompletableFuture(returnValue, returnType);
|
||||
if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler) {
|
||||
return asyncHandler.toCompletableFuture(returnValue, returnType);
|
||||
}
|
||||
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");
|
||||
* 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() {
|
||||
synchronized (this) {
|
||||
Object item = this.item;
|
||||
if (item instanceof DataBuffer) {
|
||||
DataBufferUtils.release((DataBuffer) item);
|
||||
if (item instanceof DataBuffer dataBuffer) {
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
}
|
||||
this.item = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,10 +180,10 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
|
|||
}
|
||||
|
||||
private boolean isStreamingMediaType(@Nullable MediaType mediaType) {
|
||||
if (mediaType == null || !(this.encoder instanceof HttpMessageEncoder)) {
|
||||
if (mediaType == null || !(this.encoder instanceof HttpMessageEncoder<?> httpMessageEncoder)) {
|
||||
return false;
|
||||
}
|
||||
for (MediaType streamingMediaType : ((HttpMessageEncoder<?>) this.encoder).getStreamingMediaTypes()) {
|
||||
for (MediaType streamingMediaType : httpMessageEncoder.getStreamingMediaTypes()) {
|
||||
if (mediaType.isCompatibleWith(streamingMediaType) && matchParameters(mediaType, streamingMediaType)) {
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -110,8 +110,8 @@ class JettyHeadersAdapter implements MultiValueMap<String, String> {
|
|||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return (value instanceof String &&
|
||||
this.headers.stream().anyMatch(field -> field.contains((String) value)));
|
||||
return (value instanceof String searchString &&
|
||||
this.headers.stream().anyMatch(field -> field.contains(searchString)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
|||
this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters, Log logger) {
|
||||
Assert.notNull(responseType, "'responseType' must not be null");
|
||||
Assert.notEmpty(messageConverters, "'messageConverters' must not be empty");
|
||||
Assert.noNullElements(messageConverters, "'messageConverters' must not contain null elements");
|
||||
this.responseType = responseType;
|
||||
this.responseClass = (responseType instanceof Class ? (Class<T>) responseType : null);
|
||||
this.responseClass = (responseType instanceof Class clazz ? clazz : null);
|
||||
this.messageConverters = messageConverters;
|
||||
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");
|
||||
* 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) {
|
||||
ServletRequestAttributes attributes = null;
|
||||
Object reqAttr = requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
|
||||
if (reqAttr instanceof ServletRequestAttributes) {
|
||||
attributes = (ServletRequestAttributes) reqAttr;
|
||||
if (reqAttr instanceof ServletRequestAttributes servletRequestAttributes) {
|
||||
attributes = servletRequestAttributes;
|
||||
}
|
||||
RequestAttributes threadAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (threadAttributes != null) {
|
||||
// We're assumably within the original request thread...
|
||||
LocaleContextHolder.resetLocaleContext();
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
if (attributes == null && threadAttributes instanceof ServletRequestAttributes) {
|
||||
attributes = (ServletRequestAttributes) threadAttributes;
|
||||
if (attributes == null && threadAttributes instanceof ServletRequestAttributes servletRequestAttributes) {
|
||||
attributes = servletRequestAttributes;
|
||||
}
|
||||
}
|
||||
if (attributes != null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue