Apply additional 'instanceof pattern matching' in spring-web
See gh-29530
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user