{"record":{"id":"27d060060075f026","repo":"chinabugotech/hutool","slug":"paths-or-ins-is-empty","errorCode":null,"errorMessage":"Paths or ins is empty !","messagePattern":"Paths or ins is empty !","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/compress/ZipWriter.java","lineNumber":195,"sourceCode":"\t\t\t}\n\t\t}\n\n\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);","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/compress/ZipWriter.java#L177-L213","documentation":"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.","triggerScenarios":"Invoking the bulk add(String[], InputStream[]) overload with a null array, a zero-length array, or arrays built from an empty dynamic collection.","commonSituations":"Building paths/ins arrays from filtered streams or user inputs that can legitimately yield zero items; passing through null from upstream code.","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."],"exampleFix":"// before\nwriter.add(paths.toArray(new String[0]), ins.toArray(new InputStream[0]));\n\n// after\nif (!paths.isEmpty() && !ins.isEmpty()) {\n    writer.add(paths.toArray(new String[0]), ins.toArray(new InputStream[0]));\n}","handlingStrategy":"validation","validationCode":"if (ArrayUtil.isEmpty(paths) || ArrayUtil.isEmpty(ins)) {\n    return writer; // nothing to add\n}\nwriter.add(paths, ins);","typeGuard":null,"tryCatchPattern":"try {\n    writer.add(paths, ins);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"empty\")) { /* skip empty batch */ }\n    else throw e;\n}","preventionTips":["Always validate non-empty before the bulk add overload.","Prefer the single-entry add(path, in) loop for dynamically-sized inputs."],"tags":["zip","validation","precondition"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}