From d0fe5c24d2da8868516b20d6442efa89a7ed748b Mon Sep 17 00:00:00 2001 From: LeeJaeHoon Date: Thu, 29 Aug 2024 02:19:33 +0900 Subject: [PATCH] Apply instanceof pattern matching See gh-42049 --- .../builder/ParentContextApplicationContextInitializer.java | 5 +++-- .../boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextApplicationContextInitializer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextApplicationContextInitializer.java index 1c843b5d649..ecaee4c79a5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextApplicationContextInitializer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextApplicationContextInitializer.java @@ -72,8 +72,9 @@ public class ParentContextApplicationContextInitializer @Override public void onApplicationEvent(ContextRefreshedEvent event) { ApplicationContext context = event.getApplicationContext(); - if (context instanceof ConfigurableApplicationContext && context == event.getSource()) { - context.publishEvent(new ParentContextAvailableEvent((ConfigurableApplicationContext) context)); + if (context instanceof ConfigurableApplicationContext configurableApplicationContext + && context == event.getSource()) { + context.publishEvent(new ParentContextAvailableEvent(configurableApplicationContext)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java index 9c15b6290bd..9aa390f1f6c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java @@ -201,9 +201,8 @@ public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPost // Need a compound key flatten(properties, (Map) value, name); } - else if (value instanceof Collection) { + else if (value instanceof Collection collection) { // Need a compound key - Collection collection = (Collection) value; properties.put(name, StringUtils.collectionToCommaDelimitedString(collection)); int count = 0; for (Object item : collection) {