chinabugotech/hutool · error · IllegalArgumentException
Paths length is not equals to ins length !
Error message
Paths length is not equals to ins length !
What it means
ZipWriter.add(String[] paths, InputStream[] ins) requires paths.length == ins.length so each path maps to exactly one stream. A mismatch throws IllegalArgumentException.
Source
Thrown at hutool-core/src/main/java/cn/hutool/core/compress/ZipWriter.java:198
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);
} finally {
IoUtil.close(this.out);
}View on GitHub (pinned to 8870454b2a)
Solutions
- Derive both arrays from the same source list (e.g. List<File> -> split into paths and InputStreams) so lengths always match.
- Assert paths.length == ins.length before calling add.
- Switch to the single-entry add(path, in) inside a loop indexed over one source.
Example fix
// before - arrays can drift
writer.add(pathArr, streamArr);
// after - one loop, one source
for (File f : files) {
writer.add(f.getName(), new FileInputStream(f));
} Defensive patterns
Strategy: validation
Validate before calling
if (paths.length != ins.length) {
throw new IllegalStateException("paths/ins length mismatch: " + paths.length + " vs " + ins.length);
}
writer.add(paths, ins); Try / catch
try {
writer.add(paths, ins);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("not equals")) { /* reconcile arrays */ }
else throw e;
} Prevention
- Derive paths and ins from one source list so lengths stay in sync.
- Add an assertion before the bulk call when arrays come from independent sources.
When it happens
Trigger: Calling the bulk add with two parallel arrays of different lengths, e.g. 3 paths and 2 streams.
Common situations: Maintaining two parallel arrays from independent sources that drift out of sync; off-by-one filtering applied to one array but not the other.
Related errors
- Paths or ins is empty !
- 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/cffc68f98e550052.
Report an issue: GitHub.