{"record":{"id":"3073d9d421f74b08","repo":"apache/druid","slug":"unable-to-write-s-maxsizebytes-s-is-greater","errorCode":null,"errorMessage":"Unable to write [%s], maxSizeBytes [%s] is greater than available [%s]","messagePattern":"Unable to write \\[(.+?)\\], maxSizeBytes \\[(.+?)\\] is greater than available \\[(.+?)\\]","errorType":"exception","errorClass":"IAE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/column/TypeStrategies.java","lineNumber":235,"sourceCode":"\n  /**\n   * Reads a non-null float value from a {@link ByteBuffer} at the supplied offset. This method should only be called\n   * if and only if {@link #isNullableNull} for the same offset returns false.\n   * <p>\n   * layout: | null (byte) | float |\n   * <p>\n   * This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer\n   * given to it (i.e. buffer aggs)\n   */\n  public static float readNotNullNullableFloat(ByteBuffer buffer, int offset)\n  {\n    return buffer.getFloat(offset + VALUE_OFFSET);\n  }\n\n  public static void checkMaxSize(int available, int maxSizeBytes, TypeSignature<?> signature)\n  {\n    if (maxSizeBytes > available) {\n      throw new IAE(\n          \"Unable to write [%s], maxSizeBytes [%s] is greater than available [%s]\",\n          signature.asTypeString(),\n          maxSizeBytes,\n          available\n      );\n    }\n  }\n\n  /**\n   * Read and write non-null LONG values. If reading non-null values, consider just using {@link ByteBuffer#getLong}\n   * directly, or if reading values written with {@link NullableTypeStrategy}, using {@link #isNullableNull} and\n   * {@link #readNotNullNullableLong}, both of which allow dealing in primitive long values instead of objects.\n   */\n  public static final class LongTypeStrategy implements TypeStrategy<Long>\n  {\n    @Override\n    public int estimateSizeBytes(Long value)\n    {","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/column/TypeStrategies.java#L217-L253","documentation":"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.","triggerScenarios":"Writing a value whose computed maximum serialized size exceeds the space remaining in the target ByteBuffer, via any TypeStrategy write path that calls checkMaxSize.","commonSituations":"Small in-memory buffers allocated for serialized values; very large strings/arrays/complex values; bugs in size-estimation code.","solutions":["Increase the buffer allocation so available >= maxSizeBytes for the type being written","Check buffer remaining() before writing and grow/reallocate as needed","For nested/array types, verify per-element size calculations account for offsets and null flags"],"exampleFix":"// before\nByteBuffer buf = ByteBuffer.allocate(estimate);\nstrategy.write(buf, value);\n// after\nint maxSize = strategy.getMaxLength().getMaxSizeBytes();\nByteBuffer buf = ByteBuffer.allocate(Math.max(estimate, maxSize));\nstrategy.write(buf, value);","handlingStrategy":"validation","validationCode":"int available = buffer.remaining(); int maxSize = TypeStrategies.getMaxLengthForType(signature); if (maxSize > available) { buffer = grow(buffer, maxSize); }","typeGuard":"boolean fits(ByteBuffer buf, TypeSignature<?> sig, int maxSizeBytes) { return maxSizeBytes <= buf.remaining(); }","tryCatchPattern":"try { strategy.write(buf, value); } catch (IAE e) { buf = reallocate(buf, e.getMessage()); strategy.write(buf, value); }","preventionTips":["Size buffers using the type's declared max serialized size","Account for overhead (null flags, lengths, offsets) in estimates","Unit-test serialization of maximum-size values"],"tags":["java","serialization","buffer"],"backgroundTag":"value-out-of-range","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}