{"record":{"id":"5777c99a152c511b","repo":"kestra-io/kestra","slug":"cannot-create-a-working-directory-file-with-a-null","errorCode":null,"errorMessage":"Cannot create a working directory file with a null or empty name","messagePattern":"Cannot create a working directory file with a null or empty name","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/LocalWorkingDir.java","lineNumber":164,"sourceCode":"    public Path createFile(String filename) throws IOException {\n        return createFile(filename, (InputStream) null);\n    }\n\n    /**\n     * {@inheritDoc}\n     **/\n    @Override\n    public Path createFile(String filename, byte[] content) throws IOException {\n        return createFile(filename, content == null ? null : new ByteArrayInputStream(content));\n    }\n\n    /**\n     * {@inheritDoc}\n     **/\n    @Override\n    public Path createFile(String filename, InputStream content) throws IOException {\n        if (filename == null || filename.isBlank()) {\n            throw new IllegalArgumentException(\"Cannot create a working directory file with a null or empty name\");\n        }\n        Path newFilePath = this.resolve(Path.of(filename));\n        Files.createDirectories(newFilePath.getParent());\n\n        Files.createFile(newFilePath);\n\n        if (content != null) {\n            try (content) {\n                Files.copy(content, newFilePath, REPLACE_EXISTING);\n            }\n        }\n\n        return newFilePath;\n    }\n\n    /**\n     * {@inheritDoc}\n     **/","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/LocalWorkingDir.java#L146-L182","documentation":"Thrown by `LocalWorkingDir.createFile(String, ...)` when the filename is null or blank. `createFile` writes a new file inside the working directory; a missing name is a programming error. Thrown as `IllegalArgumentException` before any filesystem operation.","triggerScenarios":"Calling `workingDir.createFile(null, bytes)`, `workingDir.createFile(\"\", stream)`, or `workingDir.createFile(\"   \")`. The filename usually comes from a Pebble-rendered variable, an output name, or a downloaded file's name — if that source is empty/null, this fires.","commonSituations":"A download task where the remote filename header is missing; a Pebble expression that renders to empty (`{{ missing.var }}` with no default); passing `output.fileName` when the output has no filename attribute.","solutions":["Provide a non-blank filename; fall back to a generated name when the source is empty.","Use `workingDir.createTempFile()` when you do not need a specific name.","Validate the filename is non-blank before calling `createFile`."],"exampleFix":"// before\nString name = maybeName; // null\nPath p = workingDir.createFile(name, bytes);\n\n// after\nString name = (maybeName == null || maybeName.isBlank())\n    ? \"file-\" + IdUtils.create() + \".tmp\"\n    : maybeName;\nPath p = workingDir.createFile(name, bytes);","handlingStrategy":"validation","validationCode":"if (filename == null || filename.isBlank()) {\n    filename = \"file-\" + IdUtils.create() + \".tmp\";\n}\nreturn workingDir.createFile(filename, content);","typeGuard":"static boolean isValidFilename(String name) {\n    return name != null && !name.isBlank();\n}","tryCatchPattern":null,"preventionTips":["Default to a generated name when the source filename is missing.","Use `createTempFile()` when a specific name is not required.","Validate filenames derived from Pebble expressions or HTTP headers."],"tags":["working-dir","io","validation","null-check"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}