{"record":{"id":"0f5b4b90b91ce3a3","repo":"apache/hadoop","slug":"error-parsing-argument-argument-must-be-a-valid-u","errorCode":null,"errorMessage":"Error parsing argument. Argument must be a valid URI: {}","messagePattern":"Error parsing argument\\. Argument must be a valid URI: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/JobResourceUploader.java","lineNumber":544,"sourceCode":"      explorePath(conf, stringToPath(uri), limitChecker, statCache);\n    }\n\n    if (jobJar != null) {\n      explorePath(conf, stringToPath(jobJar), limitChecker, statCache);\n    }\n  }\n\n  /**\n   * Convert a String to a Path and gracefully remove fragments/queries if they\n   * exist in the String.\n   */\n  @VisibleForTesting\n  Path stringToPath(String s) {\n    try {\n      URI uri = new URI(s);\n      return new Path(uri.getScheme(), uri.getAuthority(), uri.getPath());\n    } catch (URISyntaxException e) {\n      throw new IllegalArgumentException(\n          \"Error parsing argument.\" + \" Argument must be a valid URI: \" + s, e);\n    }\n  }\n\n  @VisibleForTesting\n  protected static final String MAX_RESOURCE_ERR_MSG =\n      \"This job has exceeded the maximum number of submitted resources\";\n  @VisibleForTesting\n  protected static final String MAX_TOTAL_RESOURCE_MB_ERR_MSG =\n      \"This job has exceeded the maximum size of submitted resources\";\n  @VisibleForTesting\n  protected static final String MAX_SINGLE_RESOURCE_MB_ERR_MSG =\n      \"This job has exceeded the maximum size of a single submitted resource\";\n\n  private static class LimitChecker {\n    LimitChecker(Configuration conf) {\n      this.maxNumOfResources =\n          conf.getInt(MRJobConfig.MAX_RESOURCES,","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/JobResourceUploader.java#L526-L562","documentation":"JobResourceUploader.stringToPath(s) converts a resource string to a Path by parsing it with new URI(s) and keeping only scheme/authority/path (dropping fragments and queries). It runs during submission over cache-file/archive/libjar URIs, shared-cache libjar results, and the job jar path (mapreduce.job.jar) while the LimitChecker walks resources. Any string that java.net.URI rejects is rethrown as IllegalArgumentException('Error parsing argument. Argument must be a valid URI: <s>').","triggerScenarios":"A job jar built in a directory containing spaces (e.g. target dir 'my project/'), so the mapreduce.job.jar value is not a valid URI; cache entries added as raw filesystem strings through job.setCacheFiles? (must be URIs anyway); values that were never pre-validated because they bypassed the -files/-libjars parsing path and reach size-exploration directly.","commonSituations":"Building in a workspace path with spaces on Windows/macOS; third-party wrappers setting cache options programmatically from raw strings; shared-cache-enabled clusters reprocessing URIs that were fine as strings but not as URIs.","solutions":["Set paths through Path/URI round-trips: conf.set(MRJobConfig.JAR, new Path(jarPath).toUri().toString())","Move builds out of directories containing spaces or reserved characters","Encode components manually (%20) if a raw string is unavoidable","Unit-test your driver's conf with new URI(conf.get(...)) for every cache/jar value before deploying"],"exampleFix":"// before\nconf.set(\"mapreduce.job.jar\", \"/build/my project/app.jar\"); // space -> not a URI\n\n// after\nconf.set(\"mapreduce.job.jar\", new Path(\"/build/my project/app.jar\").toUri().toString());\n// -> file:/build/my%20project/app.jar","handlingStrategy":"validation","validationCode":"// round-trip every shipped resource string through Path before setting it\nString jar = new Path(rawJarPath).toUri().toString(); // encodes spaces etc.\nconf.set(MRJobConfig.JAR, jar);\nfor (String s : resourceStrings) {\n  new URI(s); // throws early with your own context if invalid\n}","typeGuard":"static boolean isValidCacheUri(String s) {\n  try { new URI(s); return true; }\n  catch (URISyntaxException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Build in spaces-free paths, or always normalize with Path.toUri()","Never set mapreduce.job.jar or cache entries from raw concatenated strings","Add a unit test that URI-parses every path your driver puts in the conf"],"tags":["uri","job-jar","distributed-cache","job-submission","mapreduce"],"backgroundTag":"uri-parse-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}