{"record":{"id":"538840153c3f5a03","repo":"apache/hadoop","slug":"too-many-matches","errorCode":null,"errorMessage":"Too many matches","messagePattern":"Too many matches","errorType":"exception","errorClass":"PathIOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java","lineNumber":218,"sourceCode":"   *  @param args is the list of arguments\n   *  @throws PathIOException if path doesn't exist or matches too many times \n   */\n  protected void getRemoteDestination(LinkedList<String> args)\n  throws IOException {\n    if (args.size() < 2) {\n      dst = new PathData(Path.CUR_DIR, getConf());\n    } else {\n      String pathString = args.removeLast();\n      // if the path is a glob, then it must match one and only one path\n      PathData[] items = PathData.expandAsGlob(pathString, getConf());\n      switch (items.length) {\n        case 0:\n          throw new PathNotFoundException(pathString);\n        case 1:\n          dst = items[0];\n          break;\n        default:\n          throw new PathIOException(pathString, \"Too many matches\");\n      }\n    }\n  }\n\n  @Override\n  protected void processArguments(LinkedList<PathData> args)\n  throws IOException {\n    // if more than one arg, the destination must be a directory\n    // if one arg, the dst must not exist or must be a directory\n    if (args.size() > 1) {\n      if (!dst.exists) {\n        throw new PathNotFoundException(dst.toString());\n      }\n      if (!dst.stat.isDirectory()) {\n        throw new PathIsNotDirectoryException(dst.toString());\n      }\n    } else if (dst.exists) {\n      if (!dst.stat.isDirectory() && !overwrite) {","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java#L200-L236","documentation":"Thrown by CommandWithDestination.getRemoteDestination() when the DESTINATION argument of -put/-cp/-moveFromLocal/-appendToFile is a glob that expands to more than one path (PathData.expandAsGlob returns >1 items). A copy destination must resolve to exactly one path, so PathIOException is thrown with custom text 'Too many matches'.","triggerScenarios":"'hdfs dfs -put local.txt /data/*' where /data contains several entries; a destination like '/logs/2026*' matching multiple log files; brace expansion '/out/{a,b}' resolving to two existing paths.","commonSituations":"Users globbing the destination out of habit from source-side usage; scripts reusing a wildcard for both src and dst; intending 'copy into a directory' while pointing at the directory's contents rather than the directory itself.","solutions":["Point the destination at the directory itself without wildcards ('/data/' not '/data/*')","Use a single explicit destination path or directory name that does not yet contain multiple matches","Run 'hdfs dfs -ls <dest-glob>' first and confirm exactly one result before the copy"],"exampleFix":"# before\nhdfs dfs -put local.txt /data/*\n# after\nhdfs dfs -put local.txt /data/","handlingStrategy":"validation","validationCode":"// destination glob must resolve to exactly one entry\nFileStatus[] matches = fs.globStatus(dstPattern);\nif (matches != null && matches.length > 1) {\n  throw new IOException(\"ambiguous destination, \" + matches.length + \" matches for \" + dstPattern);\n}","typeGuard":null,"tryCatchPattern":"try {\n  shellRun(\"-put\", localSrc, dstPattern);\n} catch (PathIOException e) {\n  if (\"Too many matches\".equals(e.getMessage())) {\n    // target the containing directory instead of its contents\n    shellRun(\"-put\", localSrc, dstPattern.getParent() + \"/\");\n  } else throw e;\n}","preventionTips":["Copy into the directory itself ('/data/') rather than globbing its contents ('/data/*')","Treat any destination-side wildcard as a code smell in scripts","Assert single-match with globStatus in wrappers before delegating"],"tags":["hadoop","hdfs","glob","ambiguous-match","copy","shell"],"backgroundTag":"ambiguous-glob-match","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}