{"record":{"id":"028b3705795f96c3","repo":"apache/hadoop","slug":"the-object-key-s-is-a-invalid-key-detail-s","errorCode":null,"errorMessage":"The object key %s is a invalid key, detail: %s","messagePattern":"The object key (.+?) is a invalid key, detail: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/RawFileSystem.java","lineNumber":505,"sourceCode":"          break;\n        } else {\n          throw new FileAlreadyExistsException(String.format(\"Can't make directory for path '%s',\"\n                  + \" it is a file.\", parent));\n        }\n      } catch (FileNotFoundException ignored) {\n      }\n      parent = parent.getParent();\n    } while (parent != null);\n  }\n\n  @Override\n  public FileStatus getFileStatus(Path path) throws IOException {\n    try {\n      return innerFileStatus(path);\n    } catch (ParentNotDirectoryException e) {\n      // Treat ParentNotDirectoryException as FileNotFoundException for the case that check whether\n      // path exist or not.\n      throw new FileNotFoundException(e.getMessage());\n    }\n  }\n\n\n  /**\n   * Get the file status of given path.\n   *\n   * @param f the path\n   * @return {@link RawFileStatus} describe file status info.\n   * @throws FileNotFoundException       if the path doesn't exist.\n   * @throws ParentNotDirectoryException if the path is locating under an existing file, which is\n   *                                     not allowed in directory bucket case.\n   */\n  RawFileStatus innerFileStatus(Path f) throws ParentNotDirectoryException, FileNotFoundException {\n    Path qualifiedPath = f.makeQualified(uri, workingDir);\n    RawFileStatus fileStatus = getFileStatusOrNull(qualifiedPath);\n    if (fileStatus == null) {\n      throw new FileNotFoundException(","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/RawFileSystem.java#L487-L523","documentation":"getFileStatus() converts ParentNotDirectoryException into FileNotFoundException, preserving the original message ('The object key %s is a invalid key ...'). So this message surfacing as FileNotFoundException means the path sits under an existing file (invalid key in directory-bucket terms): existence checks treat 'under a file' as 'does not exist', matching Hadoop-exists() semantics.","triggerScenarios":"fs.getFileStatus('/logs/app.txt/child') where '/logs/app.txt' exists as a file object; fs.exists() and globStatus on such paths funnel through getFileStatus and return false / empty rather than throw elsewhere.","commonSituations":"Probing a path whose prefix collides with a previously written file; recovery tools scanning for '/file/part' style keys after a layout change; code that assumes missing parents are silently treated as directories like on HDFS.","solutions":["Fix the key layout: never address children of a file object; use sibling prefixes instead","Remove or rename the file occupying the parent position, then retry","If probing existence, expect FileNotFoundException here and treat it as 'not present'"],"exampleFix":"// before\nFileStatus st = fs.getFileStatus(new Path(\"/logs/app.txt/2024\")); // '/logs/app.txt' is a file\n\n// after: keep objects and prefixes disjoint\nFileStatus st = fs.getFileStatus(new Path(\"/logs/app.txt-2024\")); // sibling, not child","handlingStrategy":"try-catch","validationCode":"// existence probe that also tolerates under-a-file paths\nFileStatus st;\ntry { st = fs.getFileStatus(p); }\ncatch (FileNotFoundException e) { st = null; } // includes parent-is-file case","typeGuard":null,"tryCatchPattern":"try { st = fs.getFileStatus(p); }\ncatch (FileNotFoundException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"is a invalid key\")) {\n    // path descends from a file object: fix the key layout\n  } else { /* ordinary missing path */ }\n}","preventionTips":["Treat under-a-file paths as nonexistent, not retryable","Assert no path component equals a known file key before probing","Prefer getFileStatusOrNull when calling RawFileSystem directly"],"tags":["invalid-object-key","path-under-file","filenotfoundexception","tos"],"backgroundTag":"invalid-object-key","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}