From 8dd385b440cb2e432ce7151be08d313982d3b00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9C=A0=EC=A7=84=28Yujin=20Choi=29/Platform=20E?= =?UTF-8?q?ngineering=ED=8C=80/11ST?= Date: Thu, 28 Oct 2021 10:58:11 +0900 Subject: [PATCH] Use toUnmodifiableSet and toList instead of collectingAndThen Since Spring Framework 6 uses JDK 17 for its baseline, we can make use of toList() and toUnmodifiableSet() which were introduced in JDK 16 and JDK 10, respectively. Closes gh-27618 --- .../springframework/beans/factory/config/YamlProcessor.java | 2 +- .../core/io/support/SpringFactoriesLoader.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java index 7949003c68b..140370b5650 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java @@ -146,7 +146,7 @@ public abstract class YamlProcessor { else { Assert.noNullElements(supportedTypes, "'supportedTypes' must not contain null elements"); this.supportedTypes = Arrays.stream(supportedTypes).map(Class::getName) - .collect(Collectors.collectingAndThen(Collectors.toSet(), Collections::unmodifiableSet)); + .collect(Collectors.toUnmodifiableSet()); } } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java index c73e775b39c..abba0cbd86e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -157,8 +156,7 @@ public final class SpringFactoriesLoader { } // Replace all lists with unmodifiable lists containing unique elements - result.replaceAll((factoryType, implementations) -> implementations.stream().distinct() - .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList))); + result.replaceAll((factoryType, implementations) -> implementations.stream().distinct().toList()); cache.put(classLoader, result); } catch (IOException ex) {