{"record":{"id":"69edcf27dc013638","repo":"apache/flink","slug":"file-status-does-not-belong-to-the-localfilesystem","errorCode":null,"errorMessage":"File status does not belong to the LocalFileSystem: {}","messagePattern":"File status does not belong to the LocalFileSystem: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java","lineNumber":91,"sourceCode":"     * cache the proper path here.\n     */\n    private final URI homeDir;\n\n    /** Constructs a new <code>LocalFileSystem</code> object. */\n    public LocalFileSystem() {\n        this.workingDir = new File(System.getProperty(\"user.dir\")).toURI();\n        this.homeDir = new File(System.getProperty(\"user.home\")).toURI();\n    }\n\n    // ------------------------------------------------------------------------\n\n    @Override\n    public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len)\n            throws IOException {\n        if (file instanceof LocalFileStatus) {\n            return ((LocalFileStatus) file).getBlockLocations();\n        }\n        throw new IOException(\"File status does not belong to the LocalFileSystem: \" + file);\n    }\n\n    @Override\n    public FileStatus getFileStatus(Path f) throws IOException {\n        final File path = pathToFile(f);\n        if (path.exists()) {\n            return new LocalFileStatus(path, this);\n        } else {\n            throw new FileNotFoundException(\n                    \"File \"\n                            + f\n                            + \" does not exist or the user running \"\n                            + \"Flink ('\"\n                            + System.getProperty(\"user.name\")\n                            + \"') has insufficient permissions to access it.\");\n        }\n    }\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java#L73-L109","documentation":"Thrown by LocalFileSystem.getFileBlockLocations() when the supplied FileStatus is not an instance of LocalFileStatus. LocalFileSystem can only return block locations for files it created/owns, because local files have no real block layout.","triggerScenarios":"Passing a FileStatus obtained from a different filesystem (e.g. HDFS, S3) into LocalFileSystem.getFileBlockLocations(file, start, len).","commonSituations":"Code that generically iterates FileStatuses from one FS and passes them to another FS's getFileBlockLocations; mocking FileStatus in tests with a non-LocalFileStatus subclass; mixing filesystem instances in input format setup.","solutions":["Call getFileBlockLocations on the same FileSystem instance that produced the FileStatus.","Ensure the FileStatus comes from LocalFileSystem.getFileStatus() or LocalFileSystem.listStatus().","Guard: `if (status instanceof LocalFileStatus)` before calling."],"exampleFix":"// before\nFileStatus s = hdfs.getFileStatus(p);\nBlockLocation[] bl = localFs.getFileBlockLocations(s, 0, len);\n\n// after\nFileStatus s = localFs.getFileStatus(p);\nBlockLocation[] bl = localFs.getFileBlockLocations(s, 0, len);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean belongsToLocalFs(FileStatus s) {\n    return s instanceof LocalFileStatus;\n}","tryCatchPattern":"try {\n    fs.getFileBlockLocations(status, 0, len);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"File status does not belong to the LocalFileSystem\")) {\n        // re-fetch status from this FS and retry\n    }\n}","preventionTips":["Always fetch FileStatus from the same FileSystem you query block locations on.","Do not pass FileStatus across filesystem instances.","In tests, use LocalFileStatus for local FS assertions."],"tags":["filesystem","local-fs","type-mismatch","input-format"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}