From d59cec9e01dd8c0c541fea3b8c87e44ac1c84010 Mon Sep 17 00:00:00 2001 From: elevne Date: Thu, 20 Jul 2023 10:37:36 +0900 Subject: [PATCH 1/2] Harmonize use of Stream in ConfigDataLocationBindHandler.onSuccess See gh-36463 --- .../config/ConfigDataLocationBindHandler.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java index 2ccf982a04..5f612d44f0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java @@ -16,6 +16,7 @@ package org.springframework.boot.context.config; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -44,23 +45,16 @@ class ConfigDataLocationBindHandler extends AbstractBindHandler { return withOrigin(context, (ConfigDataLocation) result); } if (result instanceof List) { - List list = ((List) result).stream().filter(Objects::nonNull).collect(Collectors.toList()); - for (int i = 0; i < list.size(); i++) { - Object element = list.get(i); - if (element instanceof ConfigDataLocation) { - list.set(i, withOrigin(context, (ConfigDataLocation) element)); - } - } - return list; + return ((List) result).stream() + .filter(Objects::nonNull) + .map(e -> (e instanceof ConfigDataLocation) ? withOrigin(context, (ConfigDataLocation) e) : e) + .collect(Collectors.toCollection(ArrayList::new)); } if (result instanceof ConfigDataLocation[]) { - ConfigDataLocation[] locations = Arrays.stream((ConfigDataLocation[]) result) + return Arrays.stream((ConfigDataLocation[]) result) .filter(Objects::nonNull) + .map(e -> withOrigin(context, e)) .toArray(ConfigDataLocation[]::new); - for (int i = 0; i < locations.length; i++) { - locations[i] = withOrigin(context, locations[i]); - } - return locations; } return result; } From cc77b8ace1d6c168e6bc115c43531eb5c21dde4c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 24 Jul 2023 13:14:01 +0200 Subject: [PATCH 2/2] Polish contribution See gh-36463 --- .../boot/context/config/ConfigDataLocationBindHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java index 5f612d44f0..58b8e74d99 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationBindHandler.java @@ -47,13 +47,14 @@ class ConfigDataLocationBindHandler extends AbstractBindHandler { if (result instanceof List) { return ((List) result).stream() .filter(Objects::nonNull) - .map(e -> (e instanceof ConfigDataLocation) ? withOrigin(context, (ConfigDataLocation) e) : e) + .map((element) -> (element instanceof ConfigDataLocation) + ? withOrigin(context, (ConfigDataLocation) element) : element) .collect(Collectors.toCollection(ArrayList::new)); } if (result instanceof ConfigDataLocation[]) { return Arrays.stream((ConfigDataLocation[]) result) .filter(Objects::nonNull) - .map(e -> withOrigin(context, e)) + .map((element) -> withOrigin(context, element)) .toArray(ConfigDataLocation[]::new); } return result;