diff --git a/hutool-core/src/main/java/cn/hutool/core/map/MapUtil.java b/hutool-core/src/main/java/cn/hutool/core/map/MapUtil.java index cc9088143..59b6b4f7c 100755 --- a/hutool-core/src/main/java/cn/hutool/core/map/MapUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/map/MapUtil.java @@ -2,6 +2,7 @@ package cn.hutool.core.map; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.lang.Editor; import cn.hutool.core.lang.Filter; import cn.hutool.core.lang.Pair; @@ -242,10 +243,15 @@ public class MapUtil { */ @SuppressWarnings("unchecked") public static Map createMap(Class mapType) { - if (mapType.isAssignableFrom(AbstractMap.class)) { + if (null == mapType || mapType.isAssignableFrom(AbstractMap.class)) { return new HashMap<>(); } else { - return (Map) ReflectUtil.newInstance(mapType); + try{ + return (Map) ReflectUtil.newInstance(mapType); + }catch (UtilException e){ + // 不支持的map类型,返回默认的HashMap + return new HashMap<>(); + } } } diff --git a/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java index 152370b15..ed865f415 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java @@ -836,6 +836,9 @@ public class ReflectUtil { public static T newInstance(Class clazz, Object... params) throws UtilException { if (ArrayUtil.isEmpty(params)) { final Constructor constructor = getConstructor(clazz); + if(null == constructor){ + throw new UtilException("No constructor for [{}]", clazz); + } try { return constructor.newInstance(); } catch (Exception e) { diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java index d01f51ef8..1a1ef934b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java @@ -156,6 +156,7 @@ public class ZipUtilTest { //https://github.com/dromara/hutool/issues/944 String dir = "d:/test"; String zip = "d:/test.zip"; + //noinspection IOStreamConstructor try (OutputStream out = new FileOutputStream(zip)){ //实际应用中, out 为 HttpServletResponse.getOutputStream ZipUtil.zip(out, Charset.defaultCharset(), false, null, new File(dir)); @@ -200,9 +201,10 @@ public class ZipUtilTest { } @Test - public void SizeUnzip() throws IOException { - String zipPath = "F:\\BaiduNetdiskDownload\\demo.zip"; - String outPath = "F:\\BaiduNetdiskDownload\\test"; + @Ignore + public void sizeUnzipTest() throws IOException { + String zipPath = "e:\\hutool\\demo.zip"; + String outPath = "e:\\hutool\\test"; ZipFile zipFile = new ZipFile(zipPath, Charset.forName("GBK")); File file = new File(outPath); // 限制解压文件大小为637KB diff --git a/pom.xml b/pom.xml index 2915c137f..6bffbf977 100755 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.4.0 package