{"record":{"id":"dbe32f1506200d9b","repo":"apache/druid","slug":"incrementindexschema-cannot-be-null","errorCode":null,"errorMessage":"incrementIndexSchema cannot be null","messagePattern":"incrementIndexSchema cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/incremental/AppendableIndexBuilder.java","lineNumber":112,"sourceCode":"  {\n    this.maxBytesInMemory = maxBytesInMemory;\n    return this;\n  }\n\n  public AppendableIndexBuilder setPreserveExistingMetrics(final boolean preserveExistingMetrics)\n  {\n    this.preserveExistingMetrics = preserveExistingMetrics;\n    return this;\n  }\n\n  public void validate()\n  {\n    if (maxRowCount <= 0) {\n      throw new IllegalArgumentException(\"Invalid max row count: \" + maxRowCount);\n    }\n\n    if (incrementalIndexSchema == null) {\n      throw new IllegalArgumentException(\"incrementIndexSchema cannot be null\");\n    }\n  }\n\n  public final IncrementalIndex build()\n  {\n    log.debug(\"Building appendable index.\");\n    validate();\n    return buildInner();\n  }\n\n  protected abstract IncrementalIndex buildInner();\n}\n","sourceCodeStart":94,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/incremental/AppendableIndexBuilder.java#L94-L125","documentation":"AppendableIndexBuilder.validate throws IllegalArgumentException when incrementalIndexSchema is null. Every appendable index needs a schema describing dimensions/metrics; without it the index cannot be constructed, so build() fails with this message ('incrementIndexSchema cannot be null').","triggerScenarios":"Building an IncrementalIndex with the builder without calling setIncrementalIndexSchema(...) (or the schema arg being null) before build().","commonSituations":"Programmatic index construction where schema setup was skipped or conditional code path skipped setIncrementalIndexSchema; null schema deserialized from config.","solutions":["Call setIncrementalIndexSchema(new IncrementalIndexSchema.Builder()....build()) before build()","Ensure the schema-producing code path is not returning null; add an early null check","Use DimensionSchema-based schema builders to construct a valid schema"],"exampleFix":"// before\nbuilder = new IncrementalIndex.Builder().maxRowCount(1000).build(); // no schema\n// after\nIncrementalIndexSchema schema = new IncrementalIndexSchema.Builder()\n    .withDimensionsSpec(new DimensionsSpec(null))\n    .withMetrics(...)\n    .build();\nbuilder.setIncrementalIndexSchema(schema).build();","handlingStrategy":"validation","validationCode":"if (schema == null) { throw new IllegalArgumentException(\"incrementalIndexSchema must be set before build()\"); }","typeGuard":null,"tryCatchPattern":"try { builder.validate(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"cannot be null\")) { builder.setIncrementalIndexSchema(defaultSchema()); } else { throw e; } }","preventionTips":["Construct the schema immediately after creating the builder","Assert non-null schema in helper methods wrapping the builder","Centralize index construction in one utility with mandatory schema parameter"],"tags":["java","ingestion","builder","schema"],"backgroundTag":"schema-validation-failed","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"}