diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index e5e938633e3..7b62ee1e5e8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -75,11 +75,8 @@ public abstract class TestPropertySourceUtils { static MergedTestPropertySources buildMergedTestPropertySources(Class testClass) { - return mergeTestPropertySources(findRepeatableAnnotations(testClass, TestPropertySource.class)); - } - - private static MergedTestPropertySources mergeTestPropertySources( - List> mergedAnnotations) { + List> mergedAnnotations = + findRepeatableAnnotations(testClass, TestPropertySource.class); if (mergedAnnotations.isEmpty()) { return MergedTestPropertySources.empty(); @@ -287,20 +284,15 @@ public abstract class TestPropertySourceUtils { private static void findRepeatableAnnotations( Class clazz, Class annotationType, List>> listOfLists, int[] aggregateIndex) { + // Ensure we have a list for the current aggregate index. + if (listOfLists.size() < aggregateIndex[0] + 1) { + listOfLists.add(new ArrayList<>()); + } + MergedAnnotations.from(clazz, SearchStrategy.DIRECT) .stream(annotationType) .sorted(highMetaDistancesFirst()) - .forEach(annotation -> { - List> current = null; - if (listOfLists.size() < aggregateIndex[0] + 1) { - current = new ArrayList<>(); - listOfLists.add(current); - } - else { - current = listOfLists.get(aggregateIndex[0]); - } - current.add(0, annotation); - }); + .forEach(annotation -> listOfLists.get(aggregateIndex[0]).add(0, annotation)); aggregateIndex[0]++;