apache/druid · error · IAE

Unable to write [ ], maxSizeBytes [ ] is greater than…

Error message

Unable to write [%s], maxSizeBytes [%s] is greater than available [%s]

What it means

TypeStrategies.checkMaxSize() validates that a serialized value of the given type fits into the remaining buffer space before writing. It throws IllegalArgumentException when maxSizeBytes exceeds the available bytes, preventing buffer overruns during serialization.

Solutions

  1. Increase the buffer allocation so available >= maxSizeBytes for the type being written
  2. Check buffer remaining() before writing and grow/reallocate as needed
  3. For nested/array types, verify per-element size calculations account for offsets and null flags

Example fix

// before
ByteBuffer buf = ByteBuffer.allocate(estimate);
strategy.write(buf, value);
// after
int maxSize = strategy.getMaxLength().getMaxSizeBytes();
ByteBuffer buf = ByteBuffer.allocate(Math.max(estimate, maxSize));
strategy.write(buf, value);
Defensive patterns

Strategy: validation

Validate before calling

int available = buffer.remaining(); int maxSize = TypeStrategies.getMaxLengthForType(signature); if (maxSize > available) { buffer = grow(buffer, maxSize); }

Type guard

boolean fits(ByteBuffer buf, TypeSignature<?> sig, int maxSizeBytes) { return maxSizeBytes <= buf.remaining(); }

Try / catch

try { strategy.write(buf, value); } catch (IAE e) { buf = reallocate(buf, e.getMessage()); strategy.write(buf, value); }

Prevention

When it happens

Trigger: Writing a value whose computed maximum serialized size exceeds the space remaining in the target ByteBuffer, via any TypeStrategy write path that calls checkMaxSize.

Common situations: Small in-memory buffers allocated for serialized values; very large strings/arrays/complex values; bugs in size-estimation code.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/3073d9d421f74b08. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/segment/column/TypeStrategies.java:235

  /**
   * Reads a non-null float value from a {@link ByteBuffer} at the supplied offset. This method should only be called
   * if and only if {@link #isNullableNull} for the same offset returns false.
   * <p>
   * layout: | null (byte) | float |
   * <p>
   * This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer
   * given to it (i.e. buffer aggs)
   */
  public static float readNotNullNullableFloat(ByteBuffer buffer, int offset)
  {
    return buffer.getFloat(offset + VALUE_OFFSET);
  }

  public static void checkMaxSize(int available, int maxSizeBytes, TypeSignature<?> signature)
  {
    if (maxSizeBytes > available) {
      throw new IAE(
          "Unable to write [%s], maxSizeBytes [%s] is greater than available [%s]",
          signature.asTypeString(),
          maxSizeBytes,
          available
      );
    }
  }

  /**
   * Read and write non-null LONG values. If reading non-null values, consider just using {@link ByteBuffer#getLong}
   * directly, or if reading values written with {@link NullableTypeStrategy}, using {@link #isNullableNull} and
   * {@link #readNotNullNullableLong}, both of which allow dealing in primitive long values instead of objects.
   */
  public static final class LongTypeStrategy implements TypeStrategy<Long>
  {
    @Override
    public int estimateSizeBytes(Long value)
    {

View on GitHub (pinned to 9b90983fd2)