{"record":{"id":"979db34206db8bcf","repo":"kestra-io/kestra","slug":"cannot-create-a-working-directory-file-with-an-emp","errorCode":null,"errorMessage":"Cannot create a working directory file with an empty inputStream","messagePattern":"Cannot create a working directory file with an empty inputStream","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/LocalWorkingDir.java","lineNumber":197,"sourceCode":"\n    /**\n     * {@inheritDoc}\n     **/\n    @Override\n    public Path putFile(Path path, InputStream inputStream) throws IOException {\n        return putFile(path, inputStream, FileExistComportment.OVERWRITE);\n    }\n\n    /**\n     * {@inheritDoc}\n     **/\n    @Override\n    public Path putFile(Path path, InputStream inputStream, FileExistComportment comportment) throws IOException {\n        if (path == null) {\n            throw new IllegalArgumentException(\"Cannot create a working directory file with a null path\");\n        }\n        if (inputStream == null) {\n            throw new IllegalArgumentException(\"Cannot create a working directory file with an empty inputStream\");\n        }\n        Path newFilePath = this.resolve(path);\n        Files.createDirectories(newFilePath.getParent());\n\n        if (Files.exists(newFilePath)) {\n            switch (comportment) {\n                case OVERWRITE -> {\n                    log.info(\"File {} already exist. It will be overwritten\", newFilePath);\n                    copyFile(inputStream, newFilePath);\n                }\n                case FAIL -> throw new FileAlreadyExistsException(\"File \" + newFilePath + \" already exist\");\n                case WARN -> log.warn(\"File {} already exist. It will be ignore\", newFilePath);\n                case IGNORE -> {\n                }\n            }\n        } else {\n            Files.createFile(newFilePath);\n            copyFile(inputStream, newFilePath);","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/LocalWorkingDir.java#L179-L215","documentation":"Thrown by `LocalWorkingDir.putFile(Path, InputStream, ...)` when the `inputStream` argument is null (the path is non-null at this point). Writing a file requires content; a null stream is a programming error. Thrown as `IllegalArgumentException` before any filesystem operation.","triggerScenarios":"Calling `workingDir.putFile(path, null)` — the input stream was not opened or was already closed/passed as null. Common when a fetch/transfer operation failed silently upstream and the stream variable is null.","commonSituations":"A `runContext.storage().getFile(...)` that returned null; an HTTP download whose body stream was not captured; passing a closed stream reference; refactoring that dropped the stream assignment.","solutions":["Ensure the input stream is non-null and open before calling `putFile`.","If content is optional, write an empty stream (`InputStream.nullInputStream(0)`) instead of null.","Add a null-check with a descriptive error at the call site."],"exampleFix":"// before\nInputStream in = maybeStream; // null\nworkingDir.putFile(path, in);\n\n// after\nInputStream in = Objects.requireNonNull(maybeStream, \"content stream\");\nworkingDir.putFile(path, in);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(inputStream, \"Cannot putFile: inputStream is null\");\nreturn workingDir.putFile(path, inputStream);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Open the stream immediately before writing; do not store streams in nullable fields.","Use `InputStream.nullInputStream(0)` for intentionally-empty content rather than null.","Check the result of `storage().getFile(...)` for null before passing it on."],"tags":["working-dir","io","validation","null-check","stream"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}