From 21f5d375b7a821f8c1ba5ac4ab6c91afd2124659 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 4 Apr 2024 20:14:01 -0700 Subject: [PATCH] Polish --- .../ConnectionDetailsFactories.java | 27 ++++--------------- .../boot/SpringApplicationBannerPrinter.java | 8 +++--- .../context/properties/bind/MapBinder.java | 3 +-- .../web/embedded/tomcat/GracefulShutdown.java | 1 - 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/service/connection/ConnectionDetailsFactories.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/service/connection/ConnectionDetailsFactories.java index 441590f7dce..d348238f511 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/service/connection/ConnectionDetailsFactories.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/service/connection/ConnectionDetailsFactories.java @@ -122,28 +122,11 @@ public class ConnectionDetailsFactories { @SuppressWarnings("unchecked") private static Registration get(ConnectionDetailsFactory factory) { ResolvableType type = ResolvableType.forClass(ConnectionDetailsFactory.class, factory.getClass()); - Class[] generics = resolveGenerics(type); - if (generics != null) { - return new Registration<>((Class) generics[0], (Class) generics[1], factory); - } - return null; - } - - /** - * Resolve the generics of the given {@link ResolvableType} or {@code null} if any - * of them cannot be resolved. - * @param type the type to inspect - * @return the resolved generics if they can be loaded from the classpath, - * {@code null} otherwise - */ - private static Class[] resolveGenerics(ResolvableType type) { - Class[] resolvedGenerics = type.resolveGenerics(); - for (Class genericRawType : resolvedGenerics) { - if (genericRawType == null) { - return null; - } - } - return resolvedGenerics; + Class[] generics = type.resolveGenerics(); + Class sourceType = (Class) generics[0]; + Class connectionDetailsType = (Class) generics[1]; + return (sourceType != null && connectionDetailsType != null) + ? new Registration<>(sourceType, connectionDetailsType, factory) : null; } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java index e104dedc2fc..a4bba43b86d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationBannerPrinter.java @@ -97,11 +97,11 @@ class SpringApplicationBannerPrinter { private String createStringFromBanner(Banner banner, Environment environment, Class mainApplicationClass) throws UnsupportedEncodingException { String charset = environment.getProperty("spring.banner.charset", StandardCharsets.UTF_8.name()); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (PrintStream printStream = new PrintStream(baos, false, charset)) { - banner.printBanner(environment, mainApplicationClass, printStream); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + try (PrintStream out = new PrintStream(byteArrayOutputStream, false, charset)) { + banner.printBanner(environment, mainApplicationClass, out); } - return baos.toString(charset); + return byteArrayOutputStream.toString(charset); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java index 57e6234ee75..ef0ef9757cf 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java @@ -62,8 +62,7 @@ class MapBinder extends AggregateBinder> { ConfigurationProperty property = source.getConfigurationProperty(name); if (property != null && !hasDescendants) { getContext().setConfigurationProperty(property); - Object result = property.getValue(); - result = getContext().getPlaceholdersResolver().resolvePlaceholders(result); + Object result = getContext().getPlaceholdersResolver().resolvePlaceholders(property.getValue()); return getContext().getConverter().convert(result, target); } source = source.filter(name::isAncestorOf); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/GracefulShutdown.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/GracefulShutdown.java index 8448db3b3fd..e9757f8f2a8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/GracefulShutdown.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/GracefulShutdown.java @@ -104,7 +104,6 @@ final class GracefulShutdown { } } } - } catch (InterruptedException ex) { Thread.currentThread().interrupt();