{"record":{"id":"e311e2d96831a2e6","repo":"apache/hadoop","slug":"unexpected-urisyntaxexception-e311e2","errorCode":null,"errorMessage":"unexpected URISyntaxException","messagePattern":"unexpected URISyntaxException","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java","lineNumber":87,"sourceCode":"    protected List<PathData> srcs = null;\n\n    @Override\n    protected void processOptions(LinkedList<String> args) throws IOException {\n      try {\n        CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, \"nl\",\n            \"skip-empty-file\");\n        cf.parse(args);\n\n        delimiter = cf.getOpt(\"nl\") ? \"\\n\" : null;\n        skipEmptyFileDelimiter = cf.getOpt(\"skip-empty-file\");\n\n        dst = new PathData(new URI(args.removeLast()), getConf());\n        if (dst.exists && dst.stat.isDirectory()) {\n          throw new PathIsDirectoryException(dst.toString());\n        }\n        srcs = new LinkedList<PathData>();\n      } catch (URISyntaxException e) {\n        throw new IOException(\"unexpected URISyntaxException\", e);\n      }\n    }\n\n    @Override\n    protected void processArguments(LinkedList<PathData> items)\n    throws IOException {\n      super.processArguments(items);\n      if (exitCode != 0) { // check for error collecting paths\n        return;\n      }\n      FSDataOutputStream out = dst.fs.create(dst.path);\n      try {\n        for (PathData src : srcs) {\n          if (src.stat.getLen() != 0) {\n            // Always do sequential reads.\n            try (FSDataInputStream in = src.openForSequentialIO()) {\n              IOUtils.copyBytes(in, out, getConf(), false);\n              writeDelimiter(out);","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java#L69-L105","documentation":"IOException('unexpected URISyntaxException') thrown by Getmerge.processOptions (CopyCommands.java:87). The destination argument (args.removeLast()) is parsed with 'new URI(...)' and fails because it contains characters java.net.URI rejects (spaces, unescaped %, brackets, etc.). The raw URISyntaxException is chained as the cause for the real parse position.","triggerScenarios":"'hadoop fs -getmerge /src /out put.txt' (unquoted space); a destination containing '[', ']', '|', or a bare '%' that is not a valid percent-escape; shell variables that expand to empty or to text with spaces.","commonSituations":"Unquoted shell arguments in scripts; copy/pasted Windows-style paths (C:\\dir with backslashes); templated destinations where a variable expands with whitespace; the same script works for simple names and breaks for filenames with spaces.","solutions":["Quote the argument and remove illegal characters: 'hadoop fs -getmerge /src \"/local/merged file.txt\"' will still fail — pick a name without spaces","Percent-encode reserved characters (space as %20) so 'new URI(String)' accepts the destination","Simplify the destination to letters, digits, dash, underscore, dot, slash","Print the destination variable just before the call in the failing script to see what actually expanded"],"exampleFix":"# before\nDEST=\"merged data.txt\"\nhadoop fs -getmerge /src/dir $DEST        # unexpected URISyntaxException\n\n# after\nDEST=\"merged_data.txt\"\nhadoop fs -getmerge /src/dir \"$DEST\"","handlingStrategy":"validation","validationCode":"try {\n  new URI(dstArg);\n} catch (URISyntaxException e) {\n  throw new IllegalArgumentException(\"Destination is not a valid URI: \" + dstArg, e);\n}","typeGuard":"static boolean isParsableUri(String arg) {\n  try { new URI(arg); return true; } catch (URISyntaxException e) { return false; }\n}","tryCatchPattern":"try {\n  dst = new PathData(new URI(args.removeLast()), getConf());\n} catch (URISyntaxException e) {\n  throw new IOException(\"unexpected URISyntaxException\", e);\n}","preventionTips":["Restrict destination names to URI-safe characters (alnum, '-', '_', '.', '/')","Percent-encode spaces (%20) and other reserved characters","Quote shell variables containing paths"],"tags":["hadoop","getmerge","uri","shell","syntax-error"],"backgroundTag":"uri-syntax-error","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}