apache/cassandra · error · IllegalStateException

Cannot suffix an empty path

Error message

Cannot suffix an empty path

What it means

File.withSuffix(suffix) appends a string to the file name (e.g. adding '.tmp' or '-CompressionInfo'). It throws IllegalStateException when the File was constructed with a null/empty path, since there is no name to suffix.

Source

Thrown at src/java/org/apache/cassandra/io/util/File.java:786

    public FileWriter newWriter(WriteMode mode) throws IOException
    {
        return new FileWriter(this, mode);
    }

    public FileOutputStreamPlus newOutputStream(WriteMode mode) throws NoSuchFileException
    {
        return new FileOutputStreamPlus(this, mode);
    }

    public FileInputStreamPlus newInputStream() throws NoSuchFileException
    {
        return new FileInputStreamPlus(this);
    }

    public File withSuffix(String suffix)
    {
        if (path == null)
            throw new IllegalStateException("Cannot suffix an empty path");
        return new File(path.getParent().resolve(path.getFileName().toString() + suffix));
    }

    private Path toPathForWrite()
    {
        if (path == null)
            throw new IllegalStateException("Cannot write to an empty path");
        return path;
    }

    private Path toPathForRead()
    {
        if (path == null)
            throw new IllegalStateException("Cannot read from an empty path");
        return path;
    }

    @VisibleForTesting

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Ensure the File is initialized with a real path before calling withSuffix — check where the File instance originates.
  2. Replace File.empty() usage with a concrete path or guard the call: if (file.path() != null).
  3. Fix the indirect caller (markCorrupted/absolutePath) to skip suffixing for pathless files.

Example fix

// before
File corrupted = file.withSuffix(".crc");
// after
File corrupted = file.path() == null ? null : file.withSuffix(".crc");
Defensive patterns

Strategy: type-guard

Validate before calling

// before calling
if (file.path() == null) throw new IllegalArgumentException("File has no path");

Type guard

static boolean hasPath(File f) { return f != null && f.path() != null; }

Try / catch

try { derived = file.withSuffix(".crc"); }
catch (IllegalStateException e) { derived = null; /* pathless sentinel File */ }

Prevention

When it happens

Trigger: Calling withSuffix on a File built via File.empty() or otherwise holding a null path — commonly reached indirectly through markCorrupted on an unbacked File or via absolutePath on such a File.

Common situations: Creating a placeholder File with the empty factory and later trying to derive sibling files; refactoring code that used to pass real paths but now passes File.empty(); descriptor code paths where a file handle was never assigned.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/e4bf01bc4f18ee3e. Report an issue: GitHub.