{"record":{"id":"0eb35efab1637401","repo":"apache/hadoop","slug":"mkdirs-path-arg-is-null","errorCode":null,"errorMessage":"mkdirs path arg is null","messagePattern":"mkdirs path arg is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java","lineNumber":903,"sourceCode":"\n  /**\n   * Creates the specified directory hierarchy. Does not\n   * treat existence as an error.\n   */\n  @Override\n  public boolean mkdirs(Path f) throws IOException {\n    return mkdirsWithOptionalPermission(f, null);\n  }\n\n  @Override\n  public boolean mkdirs(Path f, FsPermission permission) throws IOException {\n    return mkdirsWithOptionalPermission(f, permission);\n  }\n\n  private boolean mkdirsWithOptionalPermission(Path f, FsPermission permission)\n      throws IOException {\n    if(f == null) {\n      throw new IllegalArgumentException(\"mkdirs path arg is null\");\n    }\n    Path parent = f.getParent();\n    File p2f = pathToFile(f);\n    File parent2f = null;\n    if(parent != null) {\n      parent2f = pathToFile(parent);\n      if(parent2f != null && parent2f.exists() && !parent2f.isDirectory()) {\n        throw new ParentNotDirectoryException(\"Parent path is not a directory: \"\n            + parent);\n      }\n    }\n    if (p2f.exists() && !p2f.isDirectory()) {\n      throw new FileAlreadyExistsException(\"Destination exists\" +\n              \" and is not a directory: \" + p2f.getCanonicalPath());\n    }\n    return (parent == null || parent2f.exists() || mkdirs(parent)) &&\n      (mkOneDirWithMode(f, p2f, permission) || p2f.isDirectory());\n  }","sourceCodeStart":885,"sourceCodeEnd":921,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java#L885-L921","documentation":"RawLocalFileSystem's mkdirsWithOptionalPermission throws IllegalArgumentException('mkdirs path arg is null') when the Path argument is null, before any filesystem access. It is a fail-fast argument guard: null paths in directory creation almost always mean a caller passed an unset configuration value or an uninitialized field.","triggerScenarios":"Calling fs.mkdirs(null) or fs.mkdirs(conf.get(\"some.dir\")) where the property is unset (Configuration.get returns null), passing a null field from an object whose builder skipped the directory setting, or a Map lookup returning null.","commonSituations":"Missing <property> in core-site.xml/hdfs-site.xml read with the single-arg get(), optional builder fields never defaulted, Map<String,Path> lookups with wrong keys, or test fixtures that omit the dir entry.","solutions":["Null-check at the boundary: if (dir == null) throw new IllegalArgumentException(\"dir config missing\");","Use defaulted config reads: conf.get(\"app.data.dir\", \"/tmp/app\") so null never reaches mkdirs.","Fix the map/builder key or add the missing property to the XML.","Search the stack trace for the call site passing the null and fix the producer."],"exampleFix":"// before\nfs.mkdirs(conf.get(\"app.data.dir\")); // property unset -> null -> throws\n\n// after\nPath dataDir = new Path(conf.get(\"app.data.dir\", \"/tmp/app\"));\nfs.mkdirs(dataDir);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(dir, \"mkdirs target must not be null\");\nfs.mkdirs(dir);","typeGuard":null,"tryCatchPattern":"try {\n  fs.mkdirs(dir);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Directory configuration missing (null path)\", e);\n}","preventionTips":["Use conf.get(key, default) so unset properties never produce null paths.","Objects.requireNonNull at the entry point with a descriptive message.","Validate required configuration keys once at startup, not lazily mid-job."],"tags":["hadoop","local-filesystem","mkdirs","null-argument","illegalargumentexception","configuration"],"backgroundTag":"null-argument-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}