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 7f629bc0f..01f6c0bea 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 @@ -2560,6 +2560,9 @@ public class CollUtil { * @since 5.4.7 */ public static void forEach(Iterable iterable, Consumer consumer) { + if(iterable == null){ + return; + } forEach(iterable.iterator(), consumer); } @@ -2571,6 +2574,9 @@ public class CollUtil { * @param consumer {@link Consumer} 遍历的每条数据处理器 */ public static void forEach(Iterator iterator, Consumer consumer) { + if(iterator == null){ + return; + } int index = 0; while (iterator.hasNext()) { consumer.accept(iterator.next(), index); @@ -2586,6 +2592,9 @@ public class CollUtil { * @param consumer {@link Consumer} 遍历的每条数据处理器 */ public static void forEach(Enumeration enumeration, Consumer consumer) { + if(enumeration == null){ + return; + } int index = 0; while (enumeration.hasMoreElements()) { consumer.accept(enumeration.nextElement(), index); @@ -2603,6 +2612,9 @@ public class CollUtil { * @param kvConsumer {@link KVConsumer} 遍历的每条数据处理器 */ public static void forEach(Map map, KVConsumer kvConsumer) { + if(map == null){ + return; + } int index = 0; for (Entry entry : map.entrySet()) { kvConsumer.accept(entry.getKey(), entry.getValue(), index);