{"record":{"id":"433cdbe4d403bd13","repo":"apache/hadoop","slug":"can-not-create-a-path-from-an-empty-string","errorCode":null,"errorMessage":"Can not create a Path from an empty string","messagePattern":"Can not create a Path from an empty string","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java","lineNumber":173,"sourceCode":"        parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(),\n                      parentUri.getPath()+\"/\", null, parentUri.getFragment());\n      } catch (URISyntaxException e) {\n        throw new IllegalArgumentException(e);\n      }\n    }\n    URI resolved = parentUri.resolve(child.uri);\n    initialize(resolved.getScheme(), resolved.getAuthority(),\n               resolved.getPath(), resolved.getFragment());\n  }\n\n  private void checkPathArg( String path ) throws IllegalArgumentException {\n    // disallow construction of a Path from an empty string\n    if ( path == null ) {\n      throw new IllegalArgumentException(\n          \"Can not create a Path from a null string\");\n    }\n    if( path.length() == 0 ) {\n       throw new IllegalArgumentException(\n           \"Can not create a Path from an empty string\");\n    }   \n  }\n  \n  /**\n   * Construct a path from a String.  Path strings are URIs, but with\n   * unescaped elements and some additional normalization.\n   *\n   * @param pathString the path string\n   */\n  public Path(String pathString) throws IllegalArgumentException {\n    checkPathArg( pathString );\n    \n    // We can't use 'new URI(String)' directly, since it assumes things are\n    // escaped, which we don't require of Paths. \n    \n    // add a slash in front of paths with Windows drive letters\n    if (hasWindowsDrive(pathString) && pathString.charAt(0) != '/') {","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java#L155-L191","documentation":"org.apache.hadoop.fs.Path refuses construction from an empty string. checkPathArg() rejects zero-length input before any URI normalization, because an empty path has no meaningful filesystem location. It almost always indicates a truncated variable interpolation, an empty config value, or string manipulation that stripped all content.","triggerScenarios":"Calling new Path(\"\") directly, new Path(conf.get(\"key\")) where the property exists but is empty (<value></value>), a concatenation like base + \"/\" + name where both parts are empty, or trimming user input that reduces to an empty string.","commonSituations":"core-site.xml with <property><name>fs.defaultFS</name><value></value></property>, a shell script exporting HDFS_PATH=\"\" that the Java code reads, an empty CLI argument slot (app.sh \"\" /data), or template/placeholder substitution that produced nothing.","solutions":["Print or log the raw string right before Path construction to confirm it is empty and identify the producer.","Fix the source of the value: give the config property real content, fix the shell variable/CLI argument, or fix the concatenation logic that yielded an empty result.","Add an early guard at input boundaries (CLI parser, config loader) that rejects empty strings with a descriptive message naming the parameter.","Treat empty as 'use default' only if your protocol explicitly defines that, e.g. path = (raw == null || raw.isEmpty()) ? \"/user/me\" : raw."],"exampleFix":"// before\nPath out = new Path(args[1]); // args[1] == \"\" from a mis-quoted shell call\n\n// after\nif (args.length < 2 || args[1].trim().isEmpty()) {\n  throw new IllegalArgumentException(\"Output path argument is missing or empty\");\n}\nPath out = new Path(args[1].trim());","handlingStrategy":"validation","validationCode":"public static Path safePath(String raw, String name) {\n  if (raw == null || raw.trim().isEmpty()) {\n    throw new IllegalArgumentException(name + \" must be a non-empty path string\");\n  }\n  return new Path(raw.trim());\n}","typeGuard":null,"tryCatchPattern":"try {\n  return new Path(raw);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Empty/invalid path for parameter 'output'\", e);\n}","preventionTips":["Reject empty strings at input boundaries (CLI parser, config loader) with a named-parameter message.","When interpolating paths from shell variables or templates, assert the result is non-empty before use.","Prefer non-blank validation (trim) so whitespace-only values are caught too."],"tags":["hadoop","hdfs","path","empty-string","illegalargumentexception","configuration"],"backgroundTag":"empty-argument-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}