{"record":{"id":"0afcc48484f5d0f4","repo":"apache/druid","slug":"written-out-already-0afcc4","errorCode":null,"errorMessage":"written out already","messagePattern":"written out already","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/data/BlockLayoutColumnarLongsSerializer.java","lineNumber":102,"sourceCode":"  }\n\n  @Override\n  public void open() throws IOException\n  {\n    flattener.open();\n  }\n\n  @Override\n  public int size()\n  {\n    return numInserted;\n  }\n\n  @Override\n  public void add(long value) throws IOException\n  {\n    if (endBuffer == null) {\n      throw new IllegalStateException(\"written out already\");\n    }\n    if (numInserted == numInsertedForNextFlush) {\n      numInsertedForNextFlush += sizePer;\n      writer.flush();\n      endBuffer.flip();\n      flattener.write(endBuffer);\n      endBuffer.clear();\n      writer.setBuffer(endBuffer);\n    }\n\n    writer.write(value);\n    ++numInserted;\n    if (numInserted < 0) {\n      throw new ColumnCapacityExceededException(columnName);\n    }\n  }\n\n  @Override","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/data/BlockLayoutColumnarLongsSerializer.java#L84-L120","documentation":"BlockLayoutColumnarLongsSerializer.add(long) throws IllegalStateException(\"written out already\") when the serializer was already closed: endBuffer is null after the column data has been written out. Adds after close violate the serializer's lifecycle and would corrupt the segment, so the call fails fast.","triggerScenarios":"Calling add(long) after close() or after the underlying WriteOutBytes was flushed and buffers nulled during segment serialization.","commonSituations":"Custom extension code writing rows after segment close; reusing a finished column serializer; race conditions in concurrent ingestion plugins.","solutions":["Ensure all add(long) calls complete before closing the serializer/segment","Audit custom code for lifecycle violations (add-after-close)","Avoid reusing serializer instances across multiple segments","Add a defensive 'open' flag in wrapper code to detect late adds"],"exampleFix":"// before\nlongSerializer.add(value); // after close\n// after\nassert !isClosed : \"serializer already written out\";\nlongSerializer.add(value);","handlingStrategy":"validation","validationCode":"if (closed) {\n  throw new IllegalStateException(\"Cannot add long values after serializer close\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  serializer.add(value);\n} catch (IllegalStateException e) {\n  if (\"written out already\".equals(e.getMessage())) {\n    throw new IllegalStateException(\"Lifecycle bug: add(long) after close\", e);\n  }\n  throw e;\n}","preventionTips":["Finish all adds before closing the column","Never reuse closed serializers","Synchronize concurrent writers","Assert lifecycle order in plugin tests"],"tags":["druid","segment","illegal-state","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}