{"record":{"id":"cffc68f98e550052","repo":"chinabugotech/hutool","slug":"paths-length-is-not-equals-to-ins-length","errorCode":null,"errorMessage":"Paths length is not equals to ins length !","messagePattern":"Paths length is not equals to ins length !","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/compress/ZipWriter.java","lineNumber":198,"sourceCode":"\t\treturn putEntry(path, in);\n\t}\n\n\t/**\n\t * 对流中的数据加入到压缩文件<br>\n\t * 路径列表和流列表长度必须一致\n\t *\n\t * @param paths 流数据在压缩文件中的路径或文件名\n\t * @param ins   要压缩的源，添加完成后自动关闭流\n\t * @return 压缩文件\n\t * @throws IORuntimeException IO异常\n\t * @since 5.8.0\n\t */\n\tpublic ZipWriter add(String[] paths, InputStream[] ins) throws IORuntimeException {\n\t\tif (ArrayUtil.isEmpty(paths) || ArrayUtil.isEmpty(ins)) {\n\t\t\tthrow new IllegalArgumentException(\"Paths or ins is empty !\");\n\t\t}\n\t\tif (paths.length != ins.length) {\n\t\t\tthrow new IllegalArgumentException(\"Paths length is not equals to ins length !\");\n\t\t}\n\n\t\tfor (int i = 0; i < paths.length; i++) {\n\t\t\tadd(paths[i], ins[i]);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic void close() throws IORuntimeException {\n\t\ttry {\n\t\t\tout.finish();\n\t\t} catch (IOException e) {\n\t\t\tthrow new IORuntimeException(e);\n\t\t} finally {\n\t\t\tIoUtil.close(this.out);\n\t\t}","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/compress/ZipWriter.java#L180-L216","documentation":"ZipWriter.add(String[] paths, InputStream[] ins) requires paths.length == ins.length so each path maps to exactly one stream. A mismatch throws IllegalArgumentException.","triggerScenarios":"Calling the bulk add with two parallel arrays of different lengths, e.g. 3 paths and 2 streams.","commonSituations":"Maintaining two parallel arrays from independent sources that drift out of sync; off-by-one filtering applied to one array but not the other.","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."],"exampleFix":"// before - arrays can drift\nwriter.add(pathArr, streamArr);\n\n// after - one loop, one source\nfor (File f : files) {\n    writer.add(f.getName(), new FileInputStream(f));\n}","handlingStrategy":"validation","validationCode":"if (paths.length != ins.length) {\n    throw new IllegalStateException(\"paths/ins length mismatch: \" + paths.length + \" vs \" + ins.length);\n}\nwriter.add(paths, ins);","typeGuard":null,"tryCatchPattern":"try {\n    writer.add(paths, ins);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"not equals\")) { /* reconcile arrays */ }\n    else throw e;\n}","preventionTips":["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."],"tags":["zip","validation","precondition"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}