apache/flink · error · IllegalArgumentException

tempDirectories contains null entries

Error message

tempDirectories contains null entries

What it means

Thrown by RefCountedTmpFileCreator's constructor when one of the supplied temp directory File objects is null. The factory validates that at least one directory is present and that none are null before cloning the array for round-robin allocation.

Source

Thrown at flink-core/src/main/java/org/apache/flink/core/fs/RefCountedTmpFileCreator.java:57

 */
@Internal
public class RefCountedTmpFileCreator
        implements FunctionWithException<File, RefCountedFileWithStream, IOException> {

    private final File[] tempDirectories;

    private final AtomicInteger next;

    /**
     * Creates a new TmpReferenceCountedCreator.
     *
     * @param tempDirectories The temp directories, not null, and at least one.
     */
    private RefCountedTmpFileCreator(File... tempDirectories) {
        checkArgument(tempDirectories.length > 0, "tempDirectories must not be empty");
        for (File f : tempDirectories) {
            if (f == null) {
                throw new IllegalArgumentException("tempDirectories contains null entries");
            }
        }

        this.tempDirectories = tempDirectories.clone();
        this.next = new AtomicInteger(new Random().nextInt(this.tempDirectories.length));
    }

    /**
     * Gets the next temp file and stream to temp file. This creates the temp file atomically,
     * making sure no previous file is overwritten.
     *
     * <p>This method is safe against concurrent use.
     *
     * @return A pair of temp file and output stream to that temp file.
     * @throws IOException Thrown, if the stream to the temp file could not be opened.
     */
    @Override
    public RefCountedFileWithStream apply(File file) throws IOException {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Filter out nulls from the temp directory list before constructing: `dirs = Arrays.stream(dirs).filter(Objects::nonNull).toArray(File[]::new)`.
  2. Validate the config source(s) supplying temp directories (e.g. `io.tmp.dirs`, `taskmanager.tmp.dirs`).
  3. Default to System.getProperty("java.io.tmpdir") when a configured dir is unset.
  4. Add a startup check that all resolved temp dirs exist and are non-null.

Example fix

// before
RefCountedTmpFileCreator creator = RefCountedTmpFileCreator.of(dir1, null, dir3);

// after
File[] dirs = new File[] {dir1, dir3};
RefCountedTmpFileCreator creator = RefCountedTmpFileCreator.of(dirs);
Defensive patterns

Strategy: validation

Validate before calling

File[] cleanDirs(File... dirs) {
    File[] filtered = Arrays.stream(dirs)
        .filter(Objects::nonNull)
        .toArray(File[]::new);
    if (filtered.length == 0) throw new IllegalArgumentException("no temp dirs");
    return filtered;
}

Prevention

When it happens

Trigger: Constructing RefCountedTmpFileCreator (the factory for ref-counted temp files used by recoverable writers) with a tempDirectories array containing a null entry.

Common situations: A config option resolving to null for one of the temp dirs; parsing system temp dirs where one element is missing; programmatic construction passing an uninitialized array slot.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/4cf8b290b1734b0f. Report an issue: GitHub.