{"record":{"id":"f2df304b4a2f01ef","repo":"apache/hadoop","slug":"failed-to-create-uri-for","errorCode":null,"errorMessage":"Failed to create uri for {}","messagePattern":"Failed to create uri for (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java","lineNumber":261,"sourceCode":"  }\n  \n  /**\n   * @param str\n   *          The string array to be parsed into an URI array.\n   * @return <code>null</code> if str is <code>null</code>, else the URI array\n   *         equivalent to str.\n   * @throws IllegalArgumentException\n   *           If any string in str violates RFC&nbsp;2396.\n   */\n  public static URI[] stringToURI(String[] str){\n    if (str == null) \n      return null;\n    URI[] uris = new URI[str.length];\n    for (int i = 0; i < str.length;i++){\n      try{\n        uris[i] = new URI(str[i]);\n      }catch(URISyntaxException ur){\n        throw new IllegalArgumentException(\n            \"Failed to create uri for \" + str[i], ur);\n      }\n    }\n    return uris;\n  }\n  \n  /**\n   * stringToPath.\n   * @param str str.\n   * @return path array.\n   */\n  public static Path[] stringToPath(String[] str){\n    if (str == null) {\n      return null;\n    }\n    Path[] p = new Path[str.length];\n    for (int i = 0; i < str.length;i++){\n      p[i] = new Path(str[i]);","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java#L243-L279","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","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"],"exampleFix":"// before\nString[] paths = {\"file:/data/my files/tool.jar\"}; // space violates RFC 2396\nURI[] uris = StringUtils.stringToURI(paths);\n\n// after\nString[] paths = {new File(\"/data/my files/tool.jar\").toURI().toString()}; // file:/data/my%20files/tool.jar\nURI[] uris = StringUtils.stringToURI(paths);","handlingStrategy":"validation","validationCode":"for (String s : paths) {\n  try {\n    new URI(s); // pre-parse: surfaces exact error position\n  } catch (URISyntaxException e) {\n    throw new IllegalArgumentException(\"Bad URI in config: '\" + s + \"'\", e);\n  }\n}\nURI[] uris = StringUtils.stringToURI(paths);","typeGuard":null,"tryCatchPattern":"try { StringUtils.stringToURI(paths); } catch (IllegalArgumentException e) { URISyntaxException cause = (URISyntaxException) e.getCause(); /* cause.getIndex() locates the bad character */ }","preventionTips":["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"],"tags":["hadoop","stringutils","uri","rfc-2396","configuration"],"backgroundTag":"invalid-uri","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}