From 62deec715f881a88d540c0c96a0006e44ce7f582 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Tue, 19 May 2020 21:15:57 +0200 Subject: [PATCH] Avoid allocations in ConfigFileApplicationListener See gh-21509 --- .../boot/context/config/ConfigFileApplicationListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index c052425c0a11..8036438c0a69 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -580,10 +580,10 @@ private Resource[] getResources(String location) { private Resource[] getResourcesFromPatternLocation(String location) throws IOException { String directoryPath = location.substring(0, location.indexOf("*/")); - String fileName = location.substring(location.lastIndexOf("/") + 1); Resource resource = this.resourceLoader.getResource(directoryPath); File[] files = resource.getFile().listFiles(File::isDirectory); if (files != null) { + String fileName = location.substring(location.lastIndexOf("/") + 1); Arrays.sort(files, FILE_COMPARATOR); return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName))) .filter(Objects::nonNull).flatMap((Function>) Arrays::stream)