{"record":{"id":"149eb6e019f2cd68","repo":"apache/hadoop","slug":"invalid-directory-or-i-o-error-occurred-for-dir","errorCode":null,"errorMessage":"Invalid directory or I/O error occurred for dir: \" + dir.toString()","messagePattern":"Invalid directory or I/O error occurred for dir: \" \\+ dir\\.toString\\(\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":1602,"sourceCode":"                              \" to \" + target);\n      }\n    }\n  }\n\n  /**\n   * A wrapper for {@link File#listFiles()}. This java.io API returns null\n   * when a dir is not a directory or for any I/O error. Instead of having\n   * null check everywhere File#listFiles() is used, we will add utility API\n   * to get around this problem. For the majority of cases where we prefer\n   * an IOException to be thrown.\n   * @param dir directory for which listing should be performed\n   * @return list of files or empty list\n   * @exception IOException for invalid directory or for a bad disk.\n   */\n  public static File[] listFiles(File dir) throws IOException {\n    File[] files = dir.listFiles();\n    if(files == null) {\n      throw new IOException(\"Invalid directory or I/O error occurred for dir: \"\n                + dir.toString());\n    }\n    return files;\n  }\n\n  /**\n   * A wrapper for {@link File#list()}. This java.io API returns null\n   * when a dir is not a directory or for any I/O error. Instead of having\n   * null check everywhere File#list() is used, we will add utility API\n   * to get around this problem. For the majority of cases where we prefer\n   * an IOException to be thrown.\n   * @param dir directory for which listing should be performed\n   * @return list of file names or empty string list\n   * @exception AccessDeniedException for unreadable directory\n   * @exception IOException for invalid directory or for bad disk\n   */\n  public static String[] list(File dir) throws IOException {\n    if (!canRead(dir)) {","sourceCodeStart":1584,"sourceCodeEnd":1620,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L1584-L1620","documentation":"Error \"Invalid directory or I/O error occurred for dir: \" + dir.toString()\" thrown in apache/hadoop.","triggerScenarios":"Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:1602 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the directory exists, is a real directory, and is readable.","Check the underlying filesystem for I/O errors (dmesg, disk health)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}