{"record":{"id":"5349ba87790abc76","repo":"apache/druid","slug":"can-t-add-d-s-to-non-empty-singleentryshort2o","errorCode":null,"errorMessage":"Can't add [%d, %s] to non-empty SingleEntryShort2ObjectSortedMap[%d, %s]","messagePattern":"Can't add \\[(.+?), (.+?)\\] to non-empty SingleEntryShort2ObjectSortedMap\\[(.+?), (.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java","lineNumber":1268,"sourceCode":"          return key < 0 ? 0 : 1;\n        }\n      };\n    }\n\n    @Override\n    public V put(final short key, final V value)\n    {\n      if (isEmpty()) {\n        this.key = key;\n        this.val = value;\n        return null;\n      } else {\n        if (this.key == key) {\n          final V existing = this.val;\n          this.val = value;\n          return existing;\n        } else {\n          throw new ISE(\n              \"Can't add [%d, %s] to non-empty SingleEntryShort2ObjectSortedMap[%d, %s]\",\n              key,\n              value,\n              this.key,\n              this.val\n          );\n        }\n      }\n    }\n\n    @Override\n    public V get(short key)\n    {\n      return this.key == key ? val : null;\n    }\n\n    @Override\n    public V remove(final short key)","sourceCodeStart":1250,"sourceCodeEnd":1286,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java#L1250-L1286","documentation":"OvershadowableManager's internal SingleEntryShort2ObjectSortedMap can only hold one key/value pair. When a second entry with a different short key is added, it throws this IllegalStateException because the map has no capacity to grow — the caller must first convert the single-entry map to a full sorted map. It is an internal invariant violation indicating the bucket promotion logic should have run before the insert.","triggerScenarios":"Calling OvershadowableManager.add with a partition whose partitionId differs from the one already held in the single-entry map, when the map was not promoted to a MultiEntry map first (e.g. add called in an unexpected interleaving without going through the promote logic).","commonSituations":"Concurrency bugs where two threads add partitions to the same OvershadowableManager simultaneously; custom code or tests constructing SingleEntryShort2ObjectSortedMap directly and inserting two distinct keys; version-specific regressions in segment publishing/overshadow tracking.","solutions":["Ensure all adds to OvershadowableManager go through its synchronized/public API so the single-entry map is promoted to a multi-entry map when a second distinct key arrives","Check for concurrent access to the same OvershadowableManager and add external synchronization if multiple threads can add partitions","If constructing the map directly in tests, use a multi-entry Short2ObjectSortedMap implementation instead of the single-entry one","Upgrade Druid — interleavings that produced this were fixed in later timeline-partition refactorings"],"exampleFix":"// before\nmap.add((short) 5, chunkA);\nmap.add((short) 7, chunkB); // throws: single-entry map\n// after\nOvershadowableManager<PartitionChunk<String>> mgr = OvershadowableManager.create(0);\nmgr.add(Partitions.makeChunk(chunkA));\nmgr.add(Partitions.makeChunk(chunkB)); // manager promotes internally","handlingStrategy":"try-catch","validationCode":"if (manager.canAddHolder() /* or check existing partitionIds first */) {\n  // safe to add\n}","typeGuard":null,"tryCatchPattern":"try {\n  manager.add(chunk);\n} catch (IllegalStateException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Can't add\")) {\n    // rebuild manager from snapshot / retry under lock\n  } else throw e;\n}","preventionTips":["Only add partitions through OvershadowableManager's public synchronized API","Synchronize external access if multiple threads add partitions to the same timeline bucket","Never construct SingleEntryShort2ObjectSortedMap directly in application code"],"tags":["java","illegal-state","timeline-partitions","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}