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 448e75332..6cae48da8 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 @@ -5,6 +5,7 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.iter.ArrayIter; import cn.hutool.core.collection.iter.IterUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.reflect.ConstructorUtil; import cn.hutool.core.reflect.TypeReference; import cn.hutool.core.text.StrUtil; @@ -246,10 +247,15 @@ public class MapUtil { */ @SuppressWarnings("unchecked") public static Map createMap(final Class mapType) { - if (mapType.isAssignableFrom(AbstractMap.class)) { + if (null == mapType || mapType.isAssignableFrom(AbstractMap.class)) { return new HashMap<>(); } else { - return (Map) ConstructorUtil.newInstance(mapType); + try{ + return (Map) ConstructorUtil.newInstance(mapType); + }catch (UtilException e){ + // 不支持的map类型,返回默认的HashMap + return new HashMap<>(); + } } } diff --git a/hutool-core/src/main/java/cn/hutool/core/reflect/ConstructorUtil.java b/hutool-core/src/main/java/cn/hutool/core/reflect/ConstructorUtil.java index 6c45826b1..016274c4e 100644 --- a/hutool-core/src/main/java/cn/hutool/core/reflect/ConstructorUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/reflect/ConstructorUtil.java @@ -109,6 +109,9 @@ public class ConstructorUtil { public static T newInstance(final Class clazz, final 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 (final Exception e) { diff --git a/hutool-core/src/main/java/cn/hutool/core/stream/FastStream.java b/hutool-core/src/main/java/cn/hutool/core/stream/FastStream.java index e6aac7805..f86f62916 100644 --- a/hutool-core/src/main/java/cn/hutool/core/stream/FastStream.java +++ b/hutool-core/src/main/java/cn/hutool/core/stream/FastStream.java @@ -208,11 +208,12 @@ public class FastStream implements Stream, Iterable { * 如果两个输入流都是有序的,则结果流是有序的,如果任一输入流是并行的,则结果流是并行的。 * 当结果流关闭时,两个输入流的关闭处理程序都会被调用。 * + *

从重复串行流进行拼接时可能会导致深度调用链甚至抛出 {@code StackOverflowException}

+ * * @param 元素类型 * @param a 第一个流 * @param b 第二个流 * @return 拼接两个流之后的流 - * @implNote 从重复串行流进行拼接时可能会导致深度调用链甚至抛出 {@code StackOverflowException} */ public static FastStream concat(FastStream a, FastStream b) { return new FastStream<>(Stream.concat(a, b)); @@ -279,6 +280,7 @@ public class FastStream implements Stream, Iterable { * 过滤元素,返回与 指定操作结果 匹配 指定值 的元素组成的流 * 这是一个无状态中间操作 * + * @param 返回类型 * @param mapper 操作 * @param value 用来匹配的值 * @return 与 指定操作结果 匹配 指定值 的元素组成的流 @@ -646,10 +648,10 @@ public class FastStream implements Stream, Iterable { * @param 给定的数组类型 * @return 包含此流元素的指定的数组 * @throws ArrayStoreException 如果元素转换失败,例如不是该元素类型及其父类,则抛出该异常 - * @apiNote 例如以下代码编译正常,但运行时会抛出 {@link ArrayStoreException} - *
{@code
-	 * String[] strings = Stream.builder().add(1).build().toArray(String[]::new);
-	 * }
+ * 例如以下代码编译正常,但运行时会抛出 {@link ArrayStoreException} + *
{@code
+	 *                                                         String[] strings = Stream.builder().add(1).build().toArray(String[]::new);
+	 *                                                         }
*/ public
A[] toArray(IntFunction generator) { //noinspection SuspiciousToArrayCall @@ -658,12 +660,8 @@ public class FastStream implements Stream, Iterable { /** * 对元素进行聚合,并返回聚合后的值,相当于在for循环里写sum=sum+ints[i] - * 这是一个终端操作 - * - * @param identity 初始值,还用于限定泛型 - * @param accumulator 你想要的聚合操作 - * @return 聚合计算后的值 - * @apiNote 求和、最小值、最大值、平均值和转换成一个String字符串均为聚合操作 + * 这是一个终端操作
+ * 求和、最小值、最大值、平均值和转换成一个String字符串均为聚合操作 * 例如这里对int进行求和可以写成: * *
{@code
@@ -675,6 +673,10 @@ public class FastStream implements Stream, Iterable {
 	 * 
{@code
 	 *     Integer sum = integers.reduce(0, Integer::sum);
 	 * }
+ * + * @param identity 初始值,还用于限定泛型 + * @param accumulator 你想要的聚合操作 + * @return 聚合计算后的值 */ @Override public T reduce(T identity, BinaryOperator accumulator) { @@ -698,15 +700,15 @@ public class FastStream implements Stream, Iterable { * return foundAny ? Optional.of(result) : Optional.empty(); * }
* 但它不局限于顺序执行,例如并行流等情况下 - * 这是一个终端操作 + * 这是一个终端操作
+ * 例如以下场景抛出 NPE : + *
{@code
+	 *      Optional reduce = Stream.builder().add(1).add(1).build().reduce((a, b) -> null);
+	 * }
* * @param accumulator 你想要的聚合操作 * @return 聚合后用 {@link Optional}包裹的值 * @throws NullPointerException 如果给定的聚合操作中执行后结果为空,并用于下一次执行,则抛出该异常 - * @apiNote 例如以下场景抛出 NPE : - *
{@code
-	 *      Optional reduce = Stream.builder().add(1).add(1).build().reduce((a, b) -> null);
-	 * }
* @see #reduce(Object, BinaryOperator) * @see #min(Comparator) * @see #max(Comparator) diff --git a/pom.xml b/pom.xml index 00a67925a..194569a65 100755 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.4.0 package @@ -106,8 +106,33 @@ + + + + apiNote + a + API Note: + + + implSpec + a + Implementation Requirements: + + + implNote + a + Implementation Note: + + param + return + throws + since + version + serialData + see + + -