diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java index 46432824dd..f7fe4ed69b 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java index 482647b8e9..8cea9d4cdc 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. @@ -158,10 +158,7 @@ public class HttpComponentsClientHttpConnector implements ClientHttpConnector, C @Override public void failed(Exception ex) { - Throwable t = ex; - if (t instanceof HttpStreamResetException hsre) { - t = hsre.getCause(); - } + Throwable t = (ex instanceof HttpStreamResetException hsre ? hsre.getCause() : ex); this.sink.error(t); } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyHeadersAdapter.java index b0d2a8424a..77ec2978cf 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyHeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyHeadersAdapter.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java index 7c939d7e96..e0564dac82 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. @@ -131,9 +131,9 @@ public class JettyResourceFactory implements InitializingBean, DisposableBean { } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, - this.executor instanceof ThreadPool.SizedThreadPool sizedThreadPool - ? sizedThreadPool.getMaxThreads() / 2 - : ProcessorUtils.availableProcessors() * 2); + this.executor instanceof ThreadPool.SizedThreadPool sizedThreadPool ? + sizedThreadPool.getMaxThreads() / 2 : + ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); diff --git a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java index fecd84f8df..978e7f04c0 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java @@ -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. @@ -163,8 +163,8 @@ public class DecoderHttpMessageReader implements HttpMessageReader { protected Map getReadHints(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response) { - if (this.decoder instanceof HttpMessageDecoder httpMethodDecoder) { - return httpMethodDecoder.getDecodeHints(actualType, elementType, request, response); + if (this.decoder instanceof HttpMessageDecoder httpMessageDecoder) { + return httpMessageDecoder.getDecodeHints(actualType, elementType, request, response); } return Hints.none(); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java index 9e29096b10..12ec8b8f35 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java index 13ea0350aa..e23937943a 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java @@ -150,9 +150,9 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter toList(Collection collection) { - return collection instanceof List partList ? partList : new ArrayList<>(collection); + return (collection instanceof List list ? list : new ArrayList<>(collection)); } } diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java index 6882a647fa..4eed384a64 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java index 87bca46270..9cfe0f3d7f 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java @@ -441,24 +441,26 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure if (codec instanceof AbstractDataBufferDecoder abstractDataBufferDecoder) { abstractDataBufferDecoder.setMaxInMemorySize(size); } + // Pattern variables in the following if-blocks cannot be named the same as instance fields + // due to lacking support in Checkstyle: https://github.com/checkstyle/checkstyle/issues/10969 if (protobufPresent) { - if (codec instanceof ProtobufDecoder protobufDecoderCodec) { - protobufDecoderCodec.setMaxMessageSize(size); + if (codec instanceof ProtobufDecoder protobufDec) { + protobufDec.setMaxMessageSize(size); } } if (kotlinSerializationCborPresent) { - if (codec instanceof KotlinSerializationCborDecoder kotlinSerializationCborDecoderCodec) { - kotlinSerializationCborDecoderCodec.setMaxInMemorySize(size); + if (codec instanceof KotlinSerializationCborDecoder kotlinSerializationCborDec) { + kotlinSerializationCborDec.setMaxInMemorySize(size); } } if (kotlinSerializationJsonPresent) { - if (codec instanceof KotlinSerializationJsonDecoder kotlinSerializationJsonDecoderCodec) { - kotlinSerializationJsonDecoderCodec.setMaxInMemorySize(size); + if (codec instanceof KotlinSerializationJsonDecoder kotlinSerializationJsonDec) { + kotlinSerializationJsonDec.setMaxInMemorySize(size); } } if (kotlinSerializationProtobufPresent) { - if (codec instanceof KotlinSerializationProtobufDecoder kotlinSerializationProtobufDecoderCodec) { - kotlinSerializationProtobufDecoderCodec.setMaxInMemorySize(size); + if (codec instanceof KotlinSerializationProtobufDecoder kotlinSerializationProtobufDec) { + kotlinSerializationProtobufDec.setMaxInMemorySize(size); } } if (jackson2Present) { diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java index 2f0d768f3c..0f6a968cfd 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java @@ -69,8 +69,10 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve public MarshallingHttpMessageConverter(Marshaller marshaller) { Assert.notNull(marshaller, "Marshaller must not be null"); this.marshaller = marshaller; - if (marshaller instanceof Unmarshaller um) { - this.unmarshaller = um; + // The following pattern variable cannot be named "unmarshaller" due to lacking + // support in Checkstyle: https://github.com/checkstyle/checkstyle/issues/10969 + if (marshaller instanceof Unmarshaller _unmarshaller) { + this.unmarshaller = _unmarshaller; } } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java index c605931cf6..4cba68c3bf 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java index 7e41f423b4..4ca73c11d3 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java index 533126e683..fc6143bfda 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java index 987f879f24..b4eb5c6cd8 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. @@ -180,8 +180,8 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me public Map getMediaTypeMappings() { Map result = null; for (MediaTypeFileExtensionResolver resolver : this.resolvers) { - if (resolver instanceof MappingMediaTypeFileExtensionResolver mappingMediaTypeFileExtensionResolver) { - Map map = mappingMediaTypeFileExtensionResolver.getMediaTypes(); + if (resolver instanceof MappingMediaTypeFileExtensionResolver mappingResolver) { + Map map = mappingResolver.getMediaTypes(); if (CollectionUtils.isEmpty(map)) { continue; } diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 2928c46f81..8c3935f410 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -321,8 +321,8 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * @since 4.3 */ public void setDefaultUriVariables(Map uriVars) { - if (this.uriTemplateHandler instanceof DefaultUriBuilderFactory defaultUriVariables) { - defaultUriVariables.setDefaultUriVariables(uriVars); + if (this.uriTemplateHandler instanceof DefaultUriBuilderFactory factory) { + factory.setDefaultUriVariables(uriVars); } else { throw new IllegalArgumentException( @@ -1002,7 +1002,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } private boolean canReadResponse(Type responseType, HttpMessageConverter converter) { - Class responseClass = (responseType instanceof Class type ? type : null); + Class responseClass = (responseType instanceof Class clazz ? clazz : null); if (responseClass != null) { return converter.canRead(responseClass, null); } @@ -1052,7 +1052,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public void doWithRequest(ClientHttpRequest httpRequest) throws IOException { super.doWithRequest(httpRequest); Object requestBody = this.requestEntity.getBody(); @@ -1068,15 +1068,15 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } else { Class requestBodyClass = requestBody.getClass(); - Type requestBodyType = (this.requestEntity instanceof RequestEntity re ? - re.getType() : requestBodyClass); + // The following pattern variable cannot be named "requestEntity" due to lacking + // support in Checkstyle: https://github.com/checkstyle/checkstyle/issues/10969 + Type requestBodyType = (this.requestEntity instanceof RequestEntity _requestEntity ? + _requestEntity.getType() : requestBodyClass); HttpHeaders httpHeaders = httpRequest.getHeaders(); HttpHeaders requestHeaders = this.requestEntity.getHeaders(); MediaType requestContentType = requestHeaders.getContentType(); for (HttpMessageConverter messageConverter : getMessageConverters()) { - if (messageConverter instanceof GenericHttpMessageConverter) { - GenericHttpMessageConverter genericConverter = - (GenericHttpMessageConverter) messageConverter; + if (messageConverter instanceof GenericHttpMessageConverter genericConverter) { if (genericConverter.canWrite(requestBodyType, requestBodyClass, requestContentType)) { if (!requestHeaders.isEmpty()) { requestHeaders.forEach((key, values) -> httpHeaders.put(key, new ArrayList<>(values))); diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java b/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java index b390738b7e..e731ebd877 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextCleanupListener.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java index 34cc8fe18e..a1a9e27371 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java index 850a518705..b4aa7b0984 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index 22917a4bab..deaee9050f 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. @@ -114,14 +114,14 @@ public abstract class WebApplicationContextUtils { if (attr == null) { return null; } - if (attr instanceof RuntimeException re) { - throw re; + if (attr instanceof RuntimeException runtimeException) { + throw runtimeException; } if (attr instanceof Error error) { throw error; } - if (attr instanceof Exception ex) { - throw new IllegalStateException(ex); + if (attr instanceof Exception exception) { + throw new IllegalStateException(exception); } if (!(attr instanceof WebApplicationContext wac)) { throw new IllegalStateException("Context attribute is not of type WebApplicationContext: " + attr); @@ -152,12 +152,12 @@ public abstract class WebApplicationContextUtils { while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); Object attrValue = sc.getAttribute(attrName); - if (attrValue instanceof WebApplicationContext) { + if (attrValue instanceof WebApplicationContext currentWac) { if (wac != null) { throw new IllegalStateException("No unique WebApplicationContext found: more than one " + "DispatcherServlet registered with publishContext=true?"); } - wac = (WebApplicationContext) attrValue; + wac = currentWac; } } } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java index 6f235037f5..b7035f711f 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. diff --git a/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java b/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java index d722e4fd16..0e3bac26bd 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. diff --git a/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java b/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java index 3851a0b8bf..69a7a7a59c 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -55,8 +55,8 @@ public abstract class FacesContextUtils { if (attr == null) { return null; } - if (attr instanceof RuntimeException re) { - throw re; + if (attr instanceof RuntimeException runtimeException) { + throw runtimeException; } if (attr instanceof Error error) { throw error; diff --git a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java index 92a6189b6e..4402dd37bf 100644 --- a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java +++ b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java index 9a9d5be20d..ba47fe3d42 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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,8 +65,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { - if (returnValue instanceof Map returnValueMap) { - mavContainer.addAllAttributes(returnValueMap); + if (returnValue instanceof Map map) { + mavContainer.addAllAttributes(map); } else if (returnValue != null) { // should not happen diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java index d398e39a9c..2e3d0efd8b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java index 3a2f397da1..2aef369c69 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java index 23e8e33d66..eb5f2b3115 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java @@ -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. @@ -234,8 +234,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod Assert.state(name != null, "Unresolvable parameter name"); parameter = parameter.nestedIfOptional(); - if (value instanceof Optional optionalValue) { - value = optionalValue.orElse(null); + if (value instanceof Optional optional) { + value = optional.orElse(null); } if (value == null) { @@ -245,8 +245,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } builder.queryParam(name); } - else if (value instanceof Collection collectionValue) { - for (Object element : collectionValue) { + else if (value instanceof Collection elements) { + for (Object element : elements) { element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element); builder.queryParam(name, element); } @@ -263,8 +263,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod if (value == null) { return null; } - else if (value instanceof String stringValue) { - return stringValue; + else if (value instanceof String string) { + return string; } else if (cs != null) { return (String) cs.convert(value, sourceType, STRING_TYPE_DESCRIPTOR); diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java index 7fb074f363..c00b7923e0 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. @@ -94,8 +94,8 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe private boolean isAsyncReturnValue(@Nullable Object value, MethodParameter returnType) { for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { - if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandlerMethodReturnValueHandler && - asyncHandlerMethodReturnValueHandler.isAsyncReturnValue(value, returnType)) { + if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler && + asyncHandler.isAsyncReturnValue(value, returnType)) { return true; } } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java index 86f23d60a4..99e7ea079c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java @@ -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. @@ -208,15 +208,15 @@ public class InvocableHandlerMethod extends HandlerMethod { } catch (IllegalArgumentException ex) { assertTargetBean(method, getBean(), args); - String text = (ex.getMessage() == null || ex.getCause() instanceof NullPointerException) - ? "Illegal argument": ex.getMessage(); + String text = (ex.getMessage() == null || ex.getCause() instanceof NullPointerException) ? + "Illegal argument" : ex.getMessage(); throw new IllegalStateException(formatInvokeError(text, args), ex); } catch (InvocationTargetException ex) { // Unwrap for HandlerExceptionResolvers ... - Throwable targetException = ex.getTargetException(); - if (targetException instanceof RuntimeException re) { - throw re; + Throwable targetException = ex.getCause(); + if (targetException instanceof RuntimeException runtimeException) { + throw runtimeException; } else if (targetException instanceof Error error) { throw error; diff --git a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java index 15f9ebed29..bf5ae9f91e 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java @@ -40,7 +40,7 @@ import org.springframework.web.bind.support.SimpleSessionStatus; *

A default {@link Model} is automatically created at instantiation. * An alternate model instance may be provided via {@link #setRedirectModel} * for use in a redirect scenario. When {@link #setRedirectModelScenario} is set - * to {@code true} signalling a redirect scenario, the {@link #getModel()} + * to {@code true} signaling a redirect scenario, the {@link #getModel()} * returns the redirect model instead of the default model. * * @author Rossen Stoyanchev @@ -106,7 +106,7 @@ public class ModelAndViewContainer { */ @Nullable public String getViewName() { - return (this.view instanceof String stringView ? stringView : null); + return (this.view instanceof String viewName ? viewName : null); } /** diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java index ef2ed9bbac..4095c494e7 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java @@ -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. @@ -88,9 +88,9 @@ class MultipartFileResource extends AbstractResource { @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof MultipartFileResource multipartFileResource && - multipartFileResource.multipartFile.equals(this.multipartFile))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof MultipartFileResource other && + this.multipartFile.equals(other.multipartFile))); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java index c7bceefc28..3e35fb9622 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java index 6f16e0d945..0a6a87bada 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java @@ -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. diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index 34b45c1ab9..33cdc83416 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -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. @@ -726,8 +726,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { @Nullable private String getQueryParamValue(@Nullable Object value) { if (value != null) { - return (value instanceof Optional optionalValue ? - optionalValue.map(Object::toString).orElse(null) : + return (value instanceof Optional optional ? + optional.map(Object::toString).orElse(null) : value.toString()); } return null; @@ -740,12 +740,12 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { @Override public UriComponentsBuilder queryParamIfPresent(String name, Optional value) { - value.ifPresent(o -> { - if (o instanceof Collection elements) { - queryParam(name, elements); + value.ifPresent(v -> { + if (v instanceof Collection values) { + queryParam(name, values); } else { - queryParam(name, o); + queryParam(name, v); } }); return this; diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java index 1097e447f6..2176aad24c 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java @@ -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.