Browse Source

add null check

Looly 5 years ago
parent
commit
3f6112fcfa
2 changed files with 6 additions and 2 deletions
  1. 2 0
      CHANGELOG.md
  2. 4 2
      hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java

+ 2 - 0
CHANGELOG.md

@@ -12,6 +12,8 @@
 * 【json   】     JSONObject和JSONArray增加set方法,标识put弃用
 * 【http   】     增加SimpleHttpServer
 * 【script 】     增加createXXXScript,区别单例
+* 【core   】     修改FileUtil.writeFileToStream等方法返回值为long
+* 【core   】     CollUtil.split增加空集合判定(issue#814@Github)
 
 ### Bug修复
 * 【extra  】     修复SpringUtil使用devtools重启报错问题

+ 4 - 2
hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java

@@ -21,7 +21,6 @@ import cn.hutool.core.util.TypeUtil;
 
 import java.lang.reflect.Type;
 import java.util.AbstractCollection;
-import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -824,7 +823,7 @@ public class CollUtil {
 
 	/**
 	 * 创建Map<br>
-	 * 传入抽象Map{@link AbstractMap}和{@link Map}类将默认创建{@link HashMap}
+	 * 传入AbstractMap和{@link Map}类将默认创建{@link HashMap}
 	 *
 	 * @param <K>     map键类型
 	 * @param <V>     map值类型
@@ -923,6 +922,9 @@ public class CollUtil {
 	 */
 	public static <T> List<List<T>> split(Collection<T> collection, int size) {
 		final List<List<T>> result = new ArrayList<>();
+		if (CollUtil.isEmpty(collection)) {
+			return result;
+		}
 
 		ArrayList<T> subList = new ArrayList<>(size);
 		for (T t : collection) {