{"record":{"id":"d0ff10a1cfd80c58","repo":"apache/cassandra","slug":"cannot-write-to-an-empty-path","errorCode":null,"errorMessage":"Cannot write to an empty path","messagePattern":"Cannot write to an empty path","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/File.java","lineNumber":793,"sourceCode":"        return new FileOutputStreamPlus(this, mode);\n    }\n\n    public FileInputStreamPlus newInputStream() throws NoSuchFileException\n    {\n        return new FileInputStreamPlus(this);\n    }\n\n    public File withSuffix(String suffix)\n    {\n        if (path == null)\n            throw new IllegalStateException(\"Cannot suffix an empty path\");\n        return new File(path.getParent().resolve(path.getFileName().toString() + suffix));\n    }\n\n    private Path toPathForWrite()\n    {\n        if (path == null)\n            throw new IllegalStateException(\"Cannot write to an empty path\");\n        return path;\n    }\n\n    private Path toPathForRead()\n    {\n        if (path == null)\n            throw new IllegalStateException(\"Cannot read from an empty path\");\n        return path;\n    }\n\n    @VisibleForTesting\n    public static FileSystem unsafeGetFilesystem()\n    {\n        return filesystem;\n    }\n\n    public static void unsafeSetFilesystem(FileSystem fs)\n    {","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/File.java#L775-L811","documentation":"File's toPathForWrite() guards all write-path operations (open output streams, create/delete variants) against a File carrying a null path, throwing IllegalStateException since there is nothing to write to. This surfaces from File constructors/factories that leave path unset (e.g. File.empty()).","triggerScenarios":"Attempting to write to, create, or delete a File created via File.empty() or another pathless construction — e.g. calling file.newOutputStream(), file.delete(), or parentOf-style operations on a placeholder instance.","commonSituations":"Code paths where a File field was never assigned before use; using File.empty() as a sentinel and accidentally writing to it; initialization-order bugs in descriptors/handlers.","solutions":["Initialize the File with an actual path before any write operation — trace where the pathless instance came from.","Guard writes with if (file.path() != null) or an explicit Objects.requireNonNull check earlier in the flow.","Replace sentinel File.empty() usage with Optional<File> or a null-checked field."],"exampleFix":"// before\nout = file.newOutputStream();\n// after\nif (file.path() == null) throw new IllegalStateException(\"File not initialized before write\");\nout = file.newOutputStream();\n","handlingStrategy":"type-guard","validationCode":"if (file.path() == null) throw new IllegalStateException(\"Refusing to write to pathless File\");","typeGuard":"static boolean isWritable(File f) { return f != null && f.path() != null; }","tryCatchPattern":"try { out = file.newOutputStream(); }\ncatch (IllegalStateException e) { logger.error(\"Write on uninitialized File\"); throw e; }","preventionTips":["Ensure File fields are assigned before write phase","Avoid File.empty() sentinels in write code paths","Fail fast with explicit null-path checks at API boundaries"],"tags":["io","file","path","illegal-state"],"backgroundTag":"file-write-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}