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 76628b1973f1..28ea06922219 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 @@ -39,31 +39,22 @@ class ConfigDataLocationBindHandler extends AbstractBindHandler { @Override - @SuppressWarnings("unchecked") public Object onSuccess(ConfigurationPropertyName name, Bindable target, BindContext context, Object result) { if (result instanceof ConfigDataLocation location) { return withOrigin(context, location); } - if (result instanceof List) { - List list = ((List) result).stream() + if (result instanceof List list) { + return list.stream() .filter(Objects::nonNull) + .map((element) -> (element instanceof ConfigDataLocation location) ? withOrigin(context, location) + : element) .collect(Collectors.toCollection(ArrayList::new)); - for (int i = 0; i < list.size(); i++) { - Object element = list.get(i); - if (element instanceof ConfigDataLocation location) { - list.set(i, withOrigin(context, location)); - } - } - return list; } if (result instanceof ConfigDataLocation[] unfilteredLocations) { - ConfigDataLocation[] locations = Arrays.stream(unfilteredLocations) + return Arrays.stream(unfilteredLocations) .filter(Objects::nonNull) + .map((element) -> withOrigin(context, element)) .toArray(ConfigDataLocation[]::new); - for (int i = 0; i < locations.length; i++) { - locations[i] = withOrigin(context, locations[i]); - } - return locations; } return result; }