{"record":{"id":"8418f2b8f44b9c47","repo":"apache/hadoop","slug":"file-does-not-exist-8418f2","errorCode":null,"errorMessage":"File does not exist: {}","messagePattern":"File does not exist: (.+?)","errorType":"http","errorClass":"FileNotFoundException","httpStatus":404,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java","lineNumber":1409,"sourceCode":"      BlockLocation[] locations =\n          DFSUtilClient.locatedBlocks2Locations(locatedBlocks);\n      final String js = JsonUtil.toJsonString(locations);\n      return Response.ok(js).type(MediaType.APPLICATION_JSON).build();\n    }\n    case GET_BLOCK_LOCATIONS:\n    {\n      final long offsetValue = offset.getValue();\n      final Long lengthValue = length.getValue();\n      final LocatedBlocks locatedblocks = cp.getBlockLocations(fullpath,\n          offsetValue, lengthValue != null? lengthValue: Long.MAX_VALUE);\n      final String js = JsonUtil.toJsonString(locatedblocks);\n      return Response.ok(js).type(MediaType.APPLICATION_JSON).build();\n    }\n    case GETFILESTATUS:\n    {\n      final HdfsFileStatus status = cp.getFileInfo(fullpath);\n      if (status == null) {\n        throw new FileNotFoundException(\"File does not exist: \" + fullpath);\n      }\n\n      final String js = JsonUtil.toJsonString(status, true);\n      return Response.ok(js).type(MediaType.APPLICATION_JSON).build();\n    }\n    case LISTSTATUS:\n    {\n      final StreamingOutput streaming = getListingStream(cp, fullpath);\n      return Response.ok(streaming).type(MediaType.APPLICATION_JSON).build();\n    }\n    case GETCONTENTSUMMARY:\n    {\n      final ContentSummary contentsummary = cp.getContentSummary(fullpath);\n      final String js = JsonUtil.toJsonString(contentsummary);\n      return Response.ok(js).type(MediaType.APPLICATION_JSON).build();\n    }\n    case GETQUOTAUSAGE:\n    {","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java#L1391-L1427","documentation":"GET op=GETFILESTATUS handler. ClientProtocol.getFileInfo returns null — not an exception — when the path is absent from the namespace, so the WebHDFS layer converts null into FileNotFoundException('File does not exist: <fullpath>'), which reaches the REST client as HTTP 404 with a RemoteException body. The path in the message is the decoded full path that reached the NameNode.","triggerScenarios":"op=GETFILESTATUS on a deleted or never-created path; a path with wrong casing, a trailing space, or broken percent-encoding (unencoded %, #, ? or space); a race where another client renames/deletes the file between your listing and this status call.","commonSituations":"Monitor/polling loops racing with job cleanup that deletes outputs; doAs/user mismatch resolving a different home directory; copy-pasted URLs from logs with partial encoding; case-sensitive path mistakes after migrating from a case-insensitive filesystem.","solutions":["Verify the exact path on the same cluster and user: hdfs dfs -ls '<path>'","Percent-encode every path segment and strip whitespace/case-fix before sending","If deletion races are expected, treat the 404 as 'gone' and re-check the parent listing instead of retrying blindly","For a symlink's own status use op=GETFILELINKSTATUS; GETFILESTATUS follows the link"],"exampleFix":"// before: assumes the file still exists\nHdfsFileStatus s = webhdfs.getClient().getFileInfo(path);\n\n// after: 404 is a normal outcome when paths race with cleanup\ntry {\n  FileStatus s = webhdfs.getFileStatus(new Path(path));\n  return Optional.of(s);\n} catch (FileNotFoundException e) {\n  return Optional.empty(); // deleted between listing and fetch\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try {\n  FileStatus s = webhdfs.getFileStatus(new Path(path));\n  return Optional.of(s);\n} catch (FileNotFoundException e) { // server returned 404\n  return Optional.empty(); // absent is a valid answer — do not retry the same path\n}","preventionTips":["Percent-encode every path segment; never concatenate raw user input into the URL","In polling loops, treat 404 as a terminal state for that path rather than an error","Prefer catching FileNotFoundException over exists() pre-checks — the pre-check costs the same RPC and still races"],"tags":["webhdfs","hdfs","file-not-found","rest-api","http-404","getfilestatus"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}