{"record":{"id":"587b72d90045cc0f","repo":"apache/hadoop","slug":"file-not-found-s","errorCode":null,"errorMessage":"File not found %s","messagePattern":"File not found (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java","lineNumber":156,"sourceCode":"      return key;\n    }\n  }\n\n  private static String decode(String key) {\n    try {\n      return URLDecoder.decode(key, \"UTF-8\");\n    } catch (UnsupportedEncodingException e) {\n      LOG.warn(\"failed to decode key: {}\", key);\n      return key;\n    }\n  }\n\n  @Override\n  public ObjectContent get(String key, long offset, long limit) {\n    Preconditions.checkArgument(!Strings.isNullOrEmpty(key), \"Key should not be empty.\");\n    File file = path(encode(key)).toFile();\n    if (!file.exists()) {\n      throw new RuntimeException(String.format(\"File not found %s\", file.getAbsolutePath()));\n    }\n\n    Range range = ObjectUtils.calculateRange(offset, limit, file.length());\n    try (FileInputStream in = new FileInputStream(file)) {\n      in.skip(range.off());\n      byte[] bs = new byte[(int) range.len()];\n      in.read(bs);\n\n      byte[] fileChecksum = getFileChecksum(file.toPath());\n      return new ObjectContent(fileChecksum, new ByteArrayInputStream(bs));\n    } catch (IOException e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n  @Override\n  public byte[] put(String key, InputStreamProvider streamProvider, long contentLength) {\n    Preconditions.checkArgument(!Strings.isNullOrEmpty(key), \"Key should not be empty.\");","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java#L138-L174","documentation":"FileStore.get(key, offset, limit) maps the object key to a local file under the store root and throws this RuntimeException when that file does not exist. Unlike most filesystem APIs it is a plain RuntimeException (not FileNotFoundException), because the FileStore emulates an object store on local disk and treats a missing backing file as an unexpected invariant violation.","triggerScenarios":"storage.get(key, ...) after the object was deleted, for a key never written, when a different fs.filestore.endpoint/FILE_STORAGE_ROOT was used by the writing process, or when the key was URL-encoded differently by the writer (the store encodes keys onto paths).","commonSituations":"Test suites where each test uses a fresh temp root but a cached ObjectStorage instance still points at the old root; concurrent tests deleting shared keys; passing a URI-escaped key to get() when put() stored the unescaped form (or vice versa).","solutions":["Verify the key exists before reading: ObjectInfo info = storage.objectStatus(key); if (info == null) handle-missing","Confirm every process using the store resolves the same root (same fs.filestore.endpoint / FILE_STORAGE_ROOT env value)","Eliminate concurrent deletes of the key between listing and reading, or retry the read","Do not pre-encode/decode the key yourself — pass the same raw key string that was used with put()/uploadPart()"],"exampleFix":"// before\nObjectContent c = storage.get(key, 0, -1); // RuntimeException: File not found ...\n// after\nif (storage.objectStatus(key) == null) {\n  throw new FileNotFoundException(\"object missing: \" + key);\n}\nObjectContent c = storage.get(key, 0, -1);","handlingStrategy":"validation","validationCode":"if (storage.objectStatus(key) == null) {\n  // object absent: handle before calling get()\n  throw new java.io.FileNotFoundException(\"object missing: \" + key);\n}\nObjectContent content = storage.get(key, offset, limit);","typeGuard":null,"tryCatchPattern":"try {\n  ObjectContent content = storage.get(key, offset, limit);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"File not found\")) {\n    throw new java.io.FileNotFoundException(key); // normalize to the conventional signal\n  }\n  throw e;\n}","preventionTips":["Check existence with objectStatus(key) (returns null when absent) before get() on cold paths","Use one store root per test/process; never share keys across roots configured differently","Pass the identical raw key string used for put() — do not URL-encode/decode keys yourself","Serialize delete/read access to a key, or tolerate FileNotFoundException via retry-once logic"],"tags":["hadoop","tos","filestore","object-storage","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}