{"record":{"id":"3474411b236eae05","repo":"apache/druid","slug":"maxstringbytes-must-be-greater-than-0","errorCode":null,"errorMessage":"maxStringBytes must be greater than 0","messagePattern":"maxStringBytes must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregatorFactory.java","lineNumber":66,"sourceCode":"  private static final Comparator<String> VALUE_COMPARATOR = Comparator.nullsFirst(Comparator.naturalOrder());\n\n  private final String fieldName;\n  private final String name;\n  private final int maxStringBytes;\n  private final boolean aggregateMultipleValues;\n\n  @JsonCreator\n  public StringAnyAggregatorFactory(\n      @JsonProperty(\"name\") String name,\n      @JsonProperty(\"fieldName\") final String fieldName,\n      @JsonProperty(\"maxStringBytes\") Integer maxStringBytes,\n      @JsonProperty(\"aggregateMultipleValues\") @Nullable final Boolean aggregateMultipleValues\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    if (maxStringBytes != null && maxStringBytes < 0) {\n      throw new IAE(\"maxStringBytes must be greater than 0\");\n    }\n    this.name = name;\n    this.fieldName = fieldName;\n    this.maxStringBytes = maxStringBytes == null\n                          ? StringFirstAggregatorFactory.DEFAULT_MAX_STRING_SIZE\n                          : maxStringBytes;\n    this.aggregateMultipleValues = aggregateMultipleValues == null ? true : aggregateMultipleValues;\n  }\n\n  @Override\n  public Aggregator factorize(ColumnSelectorFactory metricFactory)\n  {\n    return new StringAnyAggregator(metricFactory.makeColumnValueSelector(fieldName), maxStringBytes, aggregateMultipleValues);\n  }\n\n  @Override\n  public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory)\n  {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/any/StringAnyAggregatorFactory.java#L48-L84","documentation":"StringAnyAggregatorFactory's constructor validates that the optional maxStringBytes parameter, when supplied, is non-negative. If a negative value is passed, Preconditions-style validation throws IAE(\"maxStringBytes must be greater than 0\") to fail fast at aggregator construction rather than at query time.","triggerScenarios":"Constructing a StringAnyAggregatorFactory (directly or via JSON ingestion/query spec deserialization) with maxStringBytes set to a negative number, e.g. {\"type\":\"any\",\"fieldName\":\"col\",\"maxStringBytes\":-1}. Note the check allows 0 (maxStringBytes < 0), so only strictly negative values throw.","commonSituations":"Copy-pasted ingestion spec with a mistyped or miscomputed maxStringBytes; a templated config where a variable resolved to a negative value; manual JSON editing of an aggregator spec.","solutions":["Set maxStringBytes to a positive integer (or omit it to use StringFirstAggregatorFactory.DEFAULT_MAX_STRING_SIZE)","Check the aggregation spec JSON for a negative maxStringBytes value and correct it","If maxStringBytes is supplied programmatically, clamp with Math.max(0, maxStringBytes) before constructing"],"exampleFix":"// before\n{\"type\":\"any\", \"name\":\"any_col\", \"fieldName\":\"col\", \"maxStringBytes\":-1}\n// after\n{\"type\":\"any\", \"name\":\"any_col\", \"fieldName\":\"col\", \"maxStringBytes\":1024}","handlingStrategy":"validation","validationCode":"if (spec.has(\"maxStringBytes\") && spec.getIntValue(\"maxStringBytes\") < 0) {\n    throw new IllegalArgumentException(\"maxStringBytes must be >= 0\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate maxStringBytes >= 0 in any config template that emits aggregator specs","Omit maxStringBytes unless a specific byte limit is required (defaults apply)","Add schema/JSON-schema validation to ingestion spec files before submission"],"tags":["java","druid","aggregation","validation"],"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"}