kestra-io/kestra · error · IllegalArgumentException

Cannot create a working directory file with an empty inputSt

Error message

Cannot create a working directory file with an empty inputStream

What it means

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.

Source

Thrown at core/src/main/java/io/kestra/core/runners/LocalWorkingDir.java:197

    /**
     * {@inheritDoc}
     **/
    @Override
    public Path putFile(Path path, InputStream inputStream) throws IOException {
        return putFile(path, inputStream, FileExistComportment.OVERWRITE);
    }

    /**
     * {@inheritDoc}
     **/
    @Override
    public Path putFile(Path path, InputStream inputStream, FileExistComportment comportment) throws IOException {
        if (path == null) {
            throw new IllegalArgumentException("Cannot create a working directory file with a null path");
        }
        if (inputStream == null) {
            throw new IllegalArgumentException("Cannot create a working directory file with an empty inputStream");
        }
        Path newFilePath = this.resolve(path);
        Files.createDirectories(newFilePath.getParent());

        if (Files.exists(newFilePath)) {
            switch (comportment) {
                case OVERWRITE -> {
                    log.info("File {} already exist. It will be overwritten", newFilePath);
                    copyFile(inputStream, newFilePath);
                }
                case FAIL -> throw new FileAlreadyExistsException("File " + newFilePath + " already exist");
                case WARN -> log.warn("File {} already exist. It will be ignore", newFilePath);
                case IGNORE -> {
                }
            }
        } else {
            Files.createFile(newFilePath);
            copyFile(inputStream, newFilePath);

View on GitHub (pinned to 823fada927)

Solutions

  1. Ensure the input stream is non-null and open before calling `putFile`.
  2. If content is optional, write an empty stream (`InputStream.nullInputStream(0)`) instead of null.
  3. Add a null-check with a descriptive error at the call site.

Example fix

// before
InputStream in = maybeStream; // null
workingDir.putFile(path, in);

// after
InputStream in = Objects.requireNonNull(maybeStream, "content stream");
workingDir.putFile(path, in);
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(inputStream, "Cannot putFile: inputStream is null");
return workingDir.putFile(path, inputStream);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/979db34206db8bcf. Report an issue: GitHub.