{"record":{"id":"ed3386bec8a15759","repo":"apache/druid","slug":"maxstringbytes-must-be-greater-than-0-ed3386","errorCode":null,"errorMessage":"maxStringBytes must be greater than 0","messagePattern":"maxStringBytes must be greater than 0","errorType":"validation","errorClass":"org.apache.druid.java.util.common.IAE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/firstlast/last/StringLastAggregatorFactory.java","lineNumber":111,"sourceCode":"\n  private final String fieldName;\n  private final String timeColumn;\n  private final String name;\n  protected final int maxStringBytes;\n\n  @JsonCreator\n  public StringLastAggregatorFactory(\n      @JsonProperty(\"name\") String name,\n      @JsonProperty(\"fieldName\") final String fieldName,\n      @JsonProperty(\"timeColumn\") @Nullable final String timeColumn,\n      @JsonProperty(\"maxStringBytes\") Integer maxStringBytes\n  )\n  {\n    Preconditions.checkNotNull(name, \"Must have a valid, non-null aggregator name\");\n    Preconditions.checkNotNull(fieldName, \"Must have a valid, non-null fieldName\");\n\n    if (maxStringBytes != null && maxStringBytes < 0) {\n      throw new IAE(\"maxStringBytes must be greater than 0\");\n    }\n\n    this.name = name;\n    this.fieldName = fieldName;\n    this.timeColumn = timeColumn == null ? ColumnHolder.TIME_COLUMN_NAME : timeColumn;\n    this.maxStringBytes = maxStringBytes == null\n                          ? StringFirstAggregatorFactory.DEFAULT_MAX_STRING_SIZE\n                          : maxStringBytes;\n  }\n\n  @Override\n  public Aggregator factorize(ColumnSelectorFactory metricFactory)\n  {\n    final BaseObjectColumnValueSelector<?> valueSelector = metricFactory.makeColumnValueSelector(fieldName);\n    if (valueSelector instanceof NilColumnValueSelector) {\n      return NIL_AGGREGATOR;\n    } else {\n      return new StringLastAggregator(","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/firstlast/last/StringLastAggregatorFactory.java#L93-L129","documentation":"StringLastAggregatorFactory's constructor validates that maxStringBytes, when supplied, is not negative, throwing IAE with message \"maxStringBytes must be greater than 0\". maxStringBytes caps the serialized size of stored strings, so a negative value is nonsensical.","triggerScenarios":"Deserializing a JSON aggregation spec with {\"type\":\"stringLast\",\"maxStringBytes\":-1} or constructing new StringLastAggregatorFactory(name, fieldName, timeColumn, negativeMaxStringBytes) programmatically. Note the guard actually triggers only for negative values (maxStringBytes < 0), not zero.","commonSituations":"Hand-written or template-generated native JSON queries with a bad variable substitution producing a negative number; SQL planner or extension code passing an unset/shifted numeric parameter; copying a spec and editing the byte limit incorrectly.","solutions":["Set maxStringBytes to a positive integer (or omit it to use the default)","Validate the config value before building the aggregation spec","Check where the value originates (query JSON, config file, variable substitution) for a sign or offset bug"],"exampleFix":"// before\n{\"type\":\"stringLast\",\"name\":\"last_user\",\"fieldName\":\"user\",\"maxStringBytes\":-1}\n// after\n{\"type\":\"stringLast\",\"name\":\"last_user\",\"fieldName\":\"user\",\"maxStringBytes\":1024}","handlingStrategy":"validation","validationCode":"if (maxStringBytes != null && maxStringBytes < 0) { throw new IllegalArgumentException(\"maxStringBytes must be >= 0\"); }","typeGuard":null,"tryCatchPattern":"try { new StringLastAggregatorFactory(name, field, timeCol, maxBytes); } catch (IAE e) { log.error(\"Bad maxStringBytes: {}\", e.getMessage()); }","preventionTips":["Validate aggregation-spec JSON fields (>= 0) before submission","Omit maxStringBytes to accept the default rather than guessing a value","Beware template/variable substitution bugs that flip numeric signs"],"tags":["java","druid","aggregation","validation","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}