From 7a1438fc02e02f658f9aa9bbc53fb80722321bba Mon Sep 17 00:00:00 2001 From: Looly Date: Sun, 28 Jun 2020 11:43:58 +0800 Subject: [PATCH] fix --- .../src/main/java/cn/hutool/core/collection/CollUtil.java | 5 ++++- .../test/java/cn/hutool/core/collection/CollUtilTest.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java index 576adabe6..db85adb28 100644 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java @@ -278,6 +278,7 @@ public class CollUtil { * @param coll2 集合2 * @param otherColls 其它集合 * @return 并集的集合,返回 {@link LinkedHashSet} + * @since 5.3.9 */ @SafeVarargs public static Set intersectionDistinct(Collection coll1, Collection coll2, Collection... otherColls) { @@ -294,7 +295,9 @@ public class CollUtil { if (ArrayUtil.isNotEmpty(otherColls)) { for (Collection otherColl : otherColls) { - result.retainAll(otherColl); + if(isNotEmpty(otherColl)){ + result.retainAll(otherColl); + } } } return result; diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java index e249602f1..450eee15d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java @@ -81,7 +81,7 @@ public class CollUtilTest { } @Test - public void intersectionTest2() { + public void intersectionDistinctTest() { ArrayList list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x"); ArrayList list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d"); ArrayList list3 = CollUtil.newArrayList();