fix(ArrayUtil): 为 copy 方法增加 null 参数防御性校验

当 src 或 dest 为 null 时,提前抛出明确的 NullPointerException,
而非让 System.arraycopy 抛出不直观的异常,便于调用方定位问题。
This commit is contained in:
Busyliu
2026-03-02 05:38:29 +00:00
committed by Gitee
parent b0375a8c04
commit 8710d04640

View File

@@ -582,6 +582,9 @@ public class ArrayUtil extends PrimitiveArrayUtil {
*/
public static Object copy(Object src, int srcPos, Object dest, int destPos, int length) {
//noinspection SuspiciousSystemArraycopy
if (null == src || null == dest) {
throw new NullPointerException("Source array and destination array must not be null");
}
System.arraycopy(src, srcPos, dest, destPos, length);
return dest;
}
@@ -598,6 +601,9 @@ public class ArrayUtil extends PrimitiveArrayUtil {
*/
public static Object copy(Object src, Object dest, int length) {
//noinspection SuspiciousSystemArraycopy
if (null == src || null == dest) {
throw new NullPointerException("Source array and destination array must not be null");
}
System.arraycopy(src, 0, dest, 0, length);
return dest;
}