{"record":{"id":"6ae0ee7f4da3f621","repo":"apache/druid","slug":"cannot-add-files-of-the-same-name-already-have","errorCode":null,"errorMessage":"Cannot add files of the same name, already have [%s]","messagePattern":"Cannot add files of the same name, already have \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/io/smoosh/FileSmoosher.java","lineNumber":150,"sourceCode":"  }\n\n  @Override\n  public void add(String name, File fileToAdd) throws IOException\n  {\n    try (MappedByteBufferHandler fileMappingHandler = FileUtils.map(fileToAdd)) {\n      add(name, fileMappingHandler.get());\n    }\n  }\n\n  @Override\n  public void add(String name, ByteBuffer bufferToAdd) throws IOException\n  {\n    if (name.contains(\",\")) {\n      throw new IAE(\"Cannot have a comma in the name of a file, got[%s].\", name);\n    }\n\n    if (internalFiles.get(name) != null) {\n      throw new IAE(\"Cannot add files of the same name, already have [%s]\", name);\n    }\n\n    long size = 0;\n    size += bufferToAdd.remaining();\n\n    try (SegmentFileChannel out = addWithChannel(name, size)) {\n      out.write(bufferToAdd);\n    }\n  }\n\n  @Override\n  public SegmentFileChannel addWithChannel(final String name, final long size) throws IOException\n  {\n    return addWithSmooshedWriter(name, size);\n  }\n\n  @Override\n  public void abort()","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/io/smoosh/FileSmoosher.java#L132-L168","documentation":"A FileSmoosher container keys its internal files by name in a map, so each name must be unique within one smoosh output. add() throws this IllegalArgumentException when you try to add a second buffer under a name that was already added to this FileSmoosher.","triggerScenarios":"Calling add(String, ByteBuffer) or addWithChannel(String, ...) twice with the same name on the same FileSmoosher instance before closing it.","commonSituations":"Re-running an add loop without changing the generated name (missing partition/counter suffix); retrying an add after a partial failure without opening a new FileSmoosher; merging data sources that produce identically named files.","solutions":["Make each name unique before adding, e.g. append an index/counter or partition id: name + \"_\" + i.","Check internalFiles contents (or track names yourself) before calling add and skip/rename duplicates.","If the duplicate indicates a logic bug, open a fresh FileSmoosher per logical unit instead of reusing one.","Deduplicate input entries before the write loop."],"exampleFix":"// before\nfor (ByteBuffer buf : buffers) {\n  smoosher.add(\"data\", buf); // duplicate name\n}\n// after\nfor (int i = 0; i < buffers.size(); i++) {\n  smoosher.add(\"data_\" + i, buffers.get(i));\n}","handlingStrategy":"validation","validationCode":"java.util.Set<String> seen = new java.util.HashSet<>();\nif (!seen.add(name)) {\n  name = name + \"_\" + seen.size(); // or skip\n}\nsmoosher.add(name, buffer);","typeGuard":null,"tryCatchPattern":"try {\n  smoosher.add(name, buffer);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot add files of the same name\")) {\n    smoosher.add(name + \"_dup\" + counter.incrementAndGet(), buffer);\n  } else { throw e; }\n}","preventionTips":["Generate names with a unique suffix (partition id, counter).","Track added names in a local Set before adding.","Don't reuse a FileSmoosher across logically separate write batches."],"tags":["io","smoosh","duplicate-key","illegal-argument"],"backgroundTag":"file-already-exists","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}