chinabugotech/hutool · error · IllegalArgumentException
Paths or ins is empty !
Error message
Paths or ins is empty !
What it means
ZipWriter.add(String[] paths, InputStream[] ins) requires both arrays to be non-empty. If either ArrayUtil.isEmpty(paths) or ArrayUtil.isEmpty(ins) is true, it throws IllegalArgumentException before writing anything.
Source
Thrown at hutool-core/src/main/java/cn/hutool/core/compress/ZipWriter.java:195
}
}
return putEntry(path, in);
}
/**
* 对流中的数据加入到压缩文件<br>
* 路径列表和流列表长度必须一致
*
* @param paths 流数据在压缩文件中的路径或文件名
* @param ins 要压缩的源,添加完成后自动关闭流
* @return 压缩文件
* @throws IORuntimeException IO异常
* @since 5.8.0
*/
public ZipWriter add(String[] paths, InputStream[] ins) throws IORuntimeException {
if (ArrayUtil.isEmpty(paths) || ArrayUtil.isEmpty(ins)) {
throw new IllegalArgumentException("Paths or ins is empty !");
}
if (paths.length != ins.length) {
throw new IllegalArgumentException("Paths length is not equals to ins length !");
}
for (int i = 0; i < paths.length; i++) {
add(paths[i], ins[i]);
}
return this;
}
@Override
public void close() throws IORuntimeException {
try {
out.finish();
} catch (IOException e) {
throw new IORuntimeException(e);View on GitHub (pinned to 8870454b2a)
Solutions
- Guard the call: only invoke add(paths, ins) when both arrays are non-null and length > 0.
- Build both arrays from the same non-empty source collection so they cannot collapse to empty.
- Use the single-entry add(path, in) in a loop when the count is dynamic or may be zero.
Example fix
// before
writer.add(paths.toArray(new String[0]), ins.toArray(new InputStream[0]));
// after
if (!paths.isEmpty() && !ins.isEmpty()) {
writer.add(paths.toArray(new String[0]), ins.toArray(new InputStream[0]));
} Defensive patterns
Strategy: validation
Validate before calling
if (ArrayUtil.isEmpty(paths) || ArrayUtil.isEmpty(ins)) {
return writer; // nothing to add
}
writer.add(paths, ins); Try / catch
try {
writer.add(paths, ins);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("empty")) { /* skip empty batch */ }
else throw e;
} Prevention
- Always validate non-empty before the bulk add overload.
- Prefer the single-entry add(path, in) loop for dynamically-sized inputs.
When it happens
Trigger: Invoking the bulk add(String[], InputStream[]) overload with a null array, a zero-length array, or arrays built from an empty dynamic collection.
Common situations: Building paths/ins arrays from filtered streams or user inputs that can legitimately yield zero items; passing through null from upstream code.
Related errors
- Paths length is not equals to ins length !
- Video URI is empty
- File not found!
- Base58 checksum is invalid
- Index [{}] is too large for limit: [{}]
AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14).
Data as JSON: /api/errors/27d060060075f026.
Report an issue: GitHub.