This commit is contained in:
Looly 2022-07-29 23:48:40 +08:00
parent 99d1835e38
commit 2e349104a3
4 changed files with 17 additions and 6 deletions

View File

@ -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 <K, V> Map<K, V> createMap(Class<?> mapType) {
if (mapType.isAssignableFrom(AbstractMap.class)) {
if (null == mapType || mapType.isAssignableFrom(AbstractMap.class)) {
return new HashMap<>();
} else {
return (Map<K, V>) ReflectUtil.newInstance(mapType);
try{
return (Map<K, V>) ReflectUtil.newInstance(mapType);
}catch (UtilException e){
// 不支持的map类型返回默认的HashMap
return new HashMap<>();
}
}
}

View File

@ -836,6 +836,9 @@ public class ReflectUtil {
public static <T> T newInstance(Class<T> clazz, Object... params) throws UtilException {
if (ArrayUtil.isEmpty(params)) {
final Constructor<T> constructor = getConstructor(clazz);
if(null == constructor){
throw new UtilException("No constructor for [{}]", clazz);
}
try {
return constructor.newInstance();
} catch (Exception e) {

View File

@ -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

View File

@ -104,7 +104,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<version>3.4.0</version>
<executions>
<execution>
<phase>package</phase>