{"record":{"id":"41511a1bb2ddfe1b","repo":"apache/hadoop","slug":"unexpected-urisyntaxexception-e","errorCode":null,"errorMessage":"Unexpected URISyntaxException: ${e}","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":370,"sourceCode":"    public void setAppendToNewBlock(boolean appendToNewBlock) {\n      this.appendToNewBlock = appendToNewBlock;\n    }\n\n    // commands operating on local paths have no need for glob expansion\n    @Override\n    protected List<PathData> expandArgument(String arg) throws IOException {\n      List<PathData> items = new LinkedList<PathData>();\n      if (arg.equals(\"-\")) {\n        readStdin = true;\n      } else {\n        try {\n          items.add(new PathData(new URI(arg), getConf()));\n        } catch (URISyntaxException e) {\n          if (Path.WINDOWS) {\n            // Unlike URI, PathData knows how to parse Windows drive-letter paths.\n            items.add(new PathData(arg, getConf()));\n          } else {\n            throw new IOException(\"Unexpected URISyntaxException: \" + e.toString());\n          }\n        }\n      }\n      return items;\n    }\n\n    @Override\n    protected void processOptions(LinkedList<String> args)\n        throws IOException {\n\n      if (args.size() < 2) {\n        throw new IOException(\"missing destination argument\");\n      }\n\n      CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, \"n\");\n      cf.parse(args);\n      appendToNewBlock = cf.getOpt(\"n\");\n      getRemoteDestination(args);","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java#L352-L388","documentation":"IOException('Unexpected URISyntaxException: ...') thrown by AppendToFile.expandArgument (CopyCommands.java:370) for 'hadoop fs -appendToFile'. A source argument that is not '-' (stdin) is parsed with 'new URI(arg)'; when that fails the code retries with PathData(String) only on Windows (Path.WINDOWS) because PathData understands drive-letter paths. On Linux/macOS the IOException is fatal and includes the URISyntaxException text.","triggerScenarios":"'hadoop fs -appendToFile \"my file.txt\" /dst' on Linux (space in name); a source containing '[', ']', or a stray '%'; Windows-style 'C:\\logs\\a.txt' passed on a Linux host; a glob the shell did not expand (quoted) containing braces/brackets.","commonSituations":"Log-ingestion scripts appending files with timestamps/spaces in names; running a script written and tested on Windows against a Linux cluster; quoted globs reaching the command unexpanded.","solutions":["Rename the file to avoid URI-reserved characters (spaces, brackets, %) before appending","Percent-encode the illegal characters in the argument (space -> %20) so new URI() parses it","Pipe the content instead: 'cat \"my file.txt\" | hadoop fs -appendToFile - /dst' ('-' bypasses URI parsing entirely)","On Windows-only flows no change is needed; on Linux avoid passing drive-letter paths"],"exampleFix":"# before (Linux)\nhadoop fs -appendToFile 'run [3].log' /logs/all    # Unexpected URISyntaxException\n\n# after\ncat 'run [3].log' | hadoop fs -appendToFile - /logs/all","handlingStrategy":"validation","validationCode":"if (!arg.equals(\"-\")) {\n  try {\n    new URI(arg);\n  } catch (URISyntaxException e) {\n    if (!Path.WINDOWS) {\n      // pipe the file instead: cat file | hadoop fs -appendToFile - dst\n      throw new IOException(\"Unexpected URISyntaxException: \" + e.toString());\n    }\n  }\n}","typeGuard":"static boolean isAppendableArgument(String arg) {\n  if (arg.equals(\"-\")) return true;\n  try { new URI(arg); return true; } catch (URISyntaxException e) { return false; }\n}","tryCatchPattern":"try {\n  items.add(new PathData(new URI(arg), getConf()));\n} catch (URISyntaxException e) {\n  if (Path.WINDOWS) {\n    items.add(new PathData(arg, getConf()));\n  } else {\n    throw new IOException(\"Unexpected URISyntaxException: \" + e.toString());\n  }\n}","preventionTips":["On Linux, avoid source names with spaces, '[', ']', or bare '%'","Pipe odd-named files via stdin: cat 'run [3].log' | hadoop fs -appendToFile - /dst","Do not pass Windows drive-letter paths on Linux hosts"],"tags":["hadoop","appendtofile","uri","shell","linux","syntax-error"],"backgroundTag":"uri-syntax-error","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}