apache/hadoop · error · IllegalArgumentException
Can not create a Path from an empty string
Error message
Can not create a Path from an empty string
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java:173
parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(),
parentUri.getPath()+"/", null, parentUri.getFragment());
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}
URI resolved = parentUri.resolve(child.uri);
initialize(resolved.getScheme(), resolved.getAuthority(),
resolved.getPath(), resolved.getFragment());
}
private void checkPathArg( String path ) throws IllegalArgumentException {
// disallow construction of a Path from an empty string
if ( path == null ) {
throw new IllegalArgumentException(
"Can not create a Path from a null string");
}
if( path.length() == 0 ) {
throw new IllegalArgumentException(
"Can not create a Path from an empty string");
}
}
/**
* Construct a path from a String. Path strings are URIs, but with
* unescaped elements and some additional normalization.
*
* @param pathString the path string
*/
public Path(String pathString) throws IllegalArgumentException {
checkPathArg( pathString );
// We can't use 'new URI(String)' directly, since it assumes things are
// escaped, which we don't require of Paths.
// add a slash in front of paths with Windows drive letters
if (hasWindowsDrive(pathString) && pathString.charAt(0) != '/') {View on GitHub (pinned to 2add963021)
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.
Example fix
// before
Path out = new Path(args[1]); // args[1] == "" from a mis-quoted shell call
// after
if (args.length < 2 || args[1].trim().isEmpty()) {
throw new IllegalArgumentException("Output path argument is missing or empty");
}
Path out = new Path(args[1].trim()); Defensive patterns
Strategy: validation
Validate before calling
public static Path safePath(String raw, String name) {
if (raw == null || raw.trim().isEmpty()) {
throw new IllegalArgumentException(name + " must be a non-empty path string");
}
return new Path(raw.trim());
} Try / catch
try {
return new Path(raw);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Empty/invalid path for parameter 'output'", e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can not create a Path from a null string
- Path part {s} from URI {p} is not a valid filename.
- mkdirs path arg is null
- Journal dir '{}' should be an absolute path
- Not a valid Boolean value for {property} in reconfSlowPeerPa
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/433cdbe4d403bd13.
Report an issue: GitHub.