From 0e31ba2fc59f337b2daea877c69b2d32b7f4f6a9 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Thu, 7 Jan 2021 11:24:05 +0800 Subject: [PATCH] =?UTF-8?q?CollUtil.forEach=20=E5=A2=9E=E5=8A=A0null=20?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/core/collection/CollUtil.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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);