diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java index c3dea336fb2..b94f19ad395 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java @@ -175,8 +175,7 @@ public class WebFluxEndpointManagementContextConfiguration { } private void process(Encoder encoder) { - if (encoder instanceof Jackson2JsonEncoder) { - Jackson2JsonEncoder jackson2JsonEncoder = (Jackson2JsonEncoder) encoder; + if (encoder instanceof Jackson2JsonEncoder jackson2JsonEncoder) { jackson2JsonEncoder.registerObjectMappersForType(OperationResponseBody.class, (associations) -> { ObjectMapper objectMapper = this.endpointObjectMapper.get().get(); MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, objectMapper)); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java index f9b7d7f0085..1ed8af92cba 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -240,10 +240,9 @@ public class JerseyEndpointResourceFactory { Status status = isGet ? Status.NOT_FOUND : Status.NO_CONTENT; return Response.status(status).build(); } - if (!(response instanceof WebEndpointResponse)) { + if (!(response instanceof WebEndpointResponse webEndpointResponse)) { return Response.status(Status.OK).entity(convertIfNecessary(response)).build(); } - WebEndpointResponse webEndpointResponse = (WebEndpointResponse) response; return Response.status(webEndpointResponse.getStatus()) .header("Content-Type", webEndpointResponse.getContentType()) .entity(convertIfNecessary(webEndpointResponse.getBody())).build(); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java index e455b23b678..d51f055e75e 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -379,10 +379,9 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi } private ResponseEntity toResponseEntity(Object response) { - if (!(response instanceof WebEndpointResponse)) { + if (!(response instanceof WebEndpointResponse webEndpointResponse)) { return new ResponseEntity<>(response, HttpStatus.OK); } - WebEndpointResponse webEndpointResponse = (WebEndpointResponse) response; MediaType contentType = (webEndpointResponse.getContentType() != null) ? new MediaType(webEndpointResponse.getContentType()) : null; return ResponseEntity.status(webEndpointResponse.getStatus()).contentType(contentType) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java index 3fbf042a136..0c75b3cb23c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -375,10 +375,9 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin return new ResponseEntity<>( (httpMethod != HttpMethod.GET) ? HttpStatus.NO_CONTENT : HttpStatus.NOT_FOUND); } - if (!(result instanceof WebEndpointResponse)) { + if (!(result instanceof WebEndpointResponse response)) { return convertIfNecessary(result); } - WebEndpointResponse response = (WebEndpointResponse) result; MediaType contentType = (response.getContentType() != null) ? new MediaType(response.getContentType()) : null; return ResponseEntity.status(response.getStatus()).contentType(contentType) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java index 42052483681..0a5fb74756f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -132,8 +132,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeAcceptCount(ConfigurableTomcatWebServerFactory factory, int acceptCount) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractProtocol) { - AbstractProtocol protocol = (AbstractProtocol) handler; + if (handler instanceof AbstractProtocol protocol) { protocol.setAcceptCount(acceptCount); } }); @@ -156,8 +155,7 @@ public class TomcatWebServerFactoryCustomizer protocol.setKeepAliveTimeout(keepAliveTimeout.toMillis()); } } - if (handler instanceof AbstractProtocol) { - AbstractProtocol protocol = (AbstractProtocol) handler; + if (handler instanceof AbstractProtocol protocol) { protocol.setKeepAliveTimeout((int) keepAliveTimeout.toMillis()); } }); @@ -166,8 +164,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeMaxKeepAliveRequests(ConfigurableTomcatWebServerFactory factory, int maxKeepAliveRequests) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractHttp11Protocol) { - AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler; + if (handler instanceof AbstractHttp11Protocol protocol) { protocol.setMaxKeepAliveRequests(maxKeepAliveRequests); } }); @@ -176,8 +173,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeMaxConnections(ConfigurableTomcatWebServerFactory factory, int maxConnections) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractProtocol) { - AbstractProtocol protocol = (AbstractProtocol) handler; + if (handler instanceof AbstractProtocol protocol) { protocol.setMaxConnections(maxConnections); } }); @@ -186,8 +182,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory factory, Duration connectionTimeout) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractProtocol) { - AbstractProtocol protocol = (AbstractProtocol) handler; + if (handler instanceof AbstractProtocol protocol) { protocol.setConnectionTimeout((int) connectionTimeout.toMillis()); } }); @@ -204,8 +199,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeRejectIllegalHeader(ConfigurableTomcatWebServerFactory factory, boolean rejectIllegalHeader) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractHttp11Protocol) { - AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler; + if (handler instanceof AbstractHttp11Protocol protocol) { protocol.setRejectIllegalHeader(rejectIllegalHeader); } }); @@ -249,15 +243,14 @@ public class TomcatWebServerFactoryCustomizer CloudPlatform platform = CloudPlatform.getActive(this.environment); return platform != null && platform.isUsingForwardHeaders(); } - return this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NATIVE); + return this.serverProperties.getForwardHeadersStrategy() == ServerProperties.ForwardHeadersStrategy.NATIVE; } @SuppressWarnings("rawtypes") private void customizeMaxThreads(ConfigurableTomcatWebServerFactory factory, int maxThreads) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractProtocol) { - AbstractProtocol protocol = (AbstractProtocol) handler; + if (handler instanceof AbstractProtocol protocol) { protocol.setMaxThreads(maxThreads); } }); @@ -267,8 +260,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeMinThreads(ConfigurableTomcatWebServerFactory factory, int minSpareThreads) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractProtocol) { - AbstractProtocol protocol = (AbstractProtocol) handler; + if (handler instanceof AbstractProtocol protocol) { protocol.setMinSpareThreads(minSpareThreads); } }); @@ -279,8 +271,7 @@ public class TomcatWebServerFactoryCustomizer int maxHttpRequestHeaderSize) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractHttp11Protocol) { - AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler; + if (handler instanceof AbstractHttp11Protocol protocol) { protocol.setMaxHttpRequestHeaderSize(maxHttpRequestHeaderSize); } }); @@ -289,8 +280,7 @@ public class TomcatWebServerFactoryCustomizer private void customizeMaxSwallowSize(ConfigurableTomcatWebServerFactory factory, int maxSwallowSize) { factory.addConnectorCustomizers((connector) -> { ProtocolHandler handler = connector.getProtocolHandler(); - if (handler instanceof AbstractHttp11Protocol) { - AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler; + if (handler instanceof AbstractHttp11Protocol protocol) { protocol.setMaxSwallowSize(maxSwallowSize); } }); diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java index 52db7dd73c7..0679a401896 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java @@ -962,8 +962,7 @@ public class TestRestTemplate { } private URI resolveUri(RequestEntity entity) { - if (entity instanceof UriTemplateRequestEntity) { - UriTemplateRequestEntity templatedUriEntity = (UriTemplateRequestEntity) entity; + if (entity instanceof UriTemplateRequestEntity templatedUriEntity) { if (templatedUriEntity.getVars() != null) { return this.restTemplate.getUriTemplateHandler().expand(templatedUriEntity.getUriTemplate(), templatedUriEntity.getVars()); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSON.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSON.java index f207c3912d1..058f5674e4d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSON.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSON.java @@ -29,8 +29,7 @@ class JSON { if (value instanceof Boolean) { return (Boolean) value; } - if (value instanceof String) { - String stringValue = (String) value; + if (value instanceof String stringValue) { if ("true".equalsIgnoreCase(stringValue)) { return true; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java index bb1cdfcf07a..a4cdb202574 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java @@ -311,8 +311,7 @@ public class JSONObject { JSON.checkDouble(((Number) value).doubleValue()); } - if (current instanceof JSONArray) { - JSONArray array = (JSONArray) current; + if (current instanceof JSONArray array) { array.put(value); } else { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java index b4b83fa858d..914496efcab 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -61,8 +61,7 @@ class NotConstructorBoundInjectionFailureAnalyzer } private boolean isConstructorBindingConfigurationProperties(InjectionPoint injectionPoint) { - if (injectionPoint != null && injectionPoint.getMember() instanceof Constructor) { - Constructor constructor = (Constructor) injectionPoint.getMember(); + if (injectionPoint != null && injectionPoint.getMember() instanceof Constructor constructor) { Class declaringClass = constructor.getDeclaringClass(); MergedAnnotation configurationProperties = MergedAnnotations.from(declaringClass) .get(ConfigurationProperties.class);