apache/hadoop · error · IllegalArgumentException
Failed to create uri for {}
Error message
Failed to create uri for {} What it means
StringUtils.stringToURI(String[]) parses each configured string into a java.net.URI (used for classpath and cache-style config lists). Any entry violating RFC 2396 — spaces, backslashes, malformed brackets — makes it throw IllegalArgumentException wrapping the URISyntaxException, naming the offending string.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java:261
}
/**
* @param str
* The string array to be parsed into an URI array.
* @return <code>null</code> if str is <code>null</code>, else the URI array
* equivalent to str.
* @throws IllegalArgumentException
* If any string in str violates RFC 2396.
*/
public static URI[] stringToURI(String[] str){
if (str == null)
return null;
URI[] uris = new URI[str.length];
for (int i = 0; i < str.length;i++){
try{
uris[i] = new URI(str[i]);
}catch(URISyntaxException ur){
throw new IllegalArgumentException(
"Failed to create uri for " + str[i], ur);
}
}
return uris;
}
/**
* stringToPath.
* @param str str.
* @return path array.
*/
public static Path[] stringToPath(String[] str){
if (str == null) {
return null;
}
Path[] p = new Path[str.length];
for (int i = 0; i < str.length;i++){
p[i] = new Path(str[i]);View on GitHub (pinned to 2add963021)
Solutions
- Build URIs properly on the producer side: new File(path).toURI().toString() percent-encodes spaces and fixes separators
- Remove or quote spaces in configured paths, or percent-encode components (my%20files)
- Convert Windows backslash paths to forward-slash URI form before passing them in
- Pre-validate each entry with new URI(s) in a unit test to surface the exact index and position of the bad string
Example fix
// before
String[] paths = {"file:/data/my files/tool.jar"}; // space violates RFC 2396
URI[] uris = StringUtils.stringToURI(paths);
// after
String[] paths = {new File("/data/my files/tool.jar").toURI().toString()}; // file:/data/my%20files/tool.jar
URI[] uris = StringUtils.stringToURI(paths); Defensive patterns
Strategy: validation
Validate before calling
for (String s : paths) {
try {
new URI(s); // pre-parse: surfaces exact error position
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Bad URI in config: '" + s + "'", e);
}
}
URI[] uris = StringUtils.stringToURI(paths); Try / catch
try { StringUtils.stringToURI(paths); } catch (IllegalArgumentException e) { URISyntaxException cause = (URISyntaxException) e.getCause(); /* cause.getIndex() locates the bad character */ } Prevention
- Generate URI strings with new File(path).toURI() or new URI(scheme, host, path, null) instead of concatenation
- Percent-encode spaces and non-ASCII in path components (my%20dir) before putting them into configs
- Convert Windows paths to forward-slash form before treating them as URIs
- Validate URI-shaped config entries in a startup lint pass so failures name the config key
When it happens
Trigger: stringToURI over config values such as job cache files or distributed-cache entries containing 'C:\dir with spaces\x.jar', 'file:/data/my files/a.jar', or hand-concatenated scheme+path strings with unescaped characters.
Common situations: Windows paths with drive letters and spaces pasted into configs; raw filesystem paths used where URI syntax is expected; configs migrated between Linux and Windows clusters; typos like 'hdfs:/ /host:8020'.
Related errors
- Bad configuration of hadoop.security.key.provider.path at ${
- Uri without authority: {uri}
- Wrong FS: {path}, expected: {this.getUri()}
- No scheme in default FS: ${uri}
- unknown scheme for endpoint:{}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/f2df304b4a2f01ef.
Report an issue: GitHub.