apache/iceberg · error
Invalid size: + size
Error message
Invalid size: + size
What it means
Thrown by ByteBuffers.writeLittleEndianUnsigned when the size argument is not 1, 2, 3, or 4. The method only knows how to write unsigned little-endian integers of those byte widths into the ByteBuffer.
Solutions
- Pass only 1, 2, 3, or 4 as size
- For 8-byte fields use buffer.putLong or a different helper (this method takes an int, so 8 bytes are unsupported)
- Validate the computed size against allowed widths before writing
- Check the file-format spec for the actual width of the field being encoded
Example fix
// before ByteBuffers.writeLittleEndianUnsigned(buf, value, offset, 8); // after ByteBuffers.writeLittleEndianUnsigned(buf, value, offset, 4); // int max 4 bytes
Defensive patterns
Strategy: validation
Validate before calling
if (size < 1 || size > 4) { throw new IllegalArgumentException("writeLittleEndianUnsigned size must be 1-4, got " + size); } Prevention
- Centralize field-width constants from the binary format spec; never compute widths inline
- Use putLong or readLittleEndianInt64 for 8-byte fields
- Unit-test read/write helpers across all supported widths
When it happens
Trigger: Calling ByteBuffers.writeLittleEndianUnsigned(buffer, value, offset, size) with size of 0, 5, 8, negative, or any value outside {1,2,3,4}.
Common situations: Code reading/writing binary file formats (e.g. Avro/Parquet metadata, footer structures) where a variable-length encoding bug computes the wrong field width; hardcoded width constants that don't match the field spec.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot bucket by type:
- AboveMax has no value
- apply(value) is deprecated, use bind(Type).apply(value)
- apply(value) is deprecated, use bind(Type).apply(value)
- Backup table name cannot be specified
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/969b68c63a9ef2ea.
Report an issue: GitHub.
Appendix: source
Thrown at api/src/main/java/org/apache/iceberg/util/ByteBuffers.java:100
public static void writeLittleEndianUnsigned(ByteBuffer buffer, int value, int offset, int size) {
int base = buffer.position() + offset;
switch (size) {
case 4:
buffer.putInt(base, value);
return;
case 3:
buffer.putShort(base, (short) (value & 0xFFFF));
buffer.put(base + 2, (byte) ((value >> 16) & 0xFF));
return;
case 2:
buffer.putShort(base, (short) (value & 0xFFFF));
return;
case 1:
buffer.put(base, (byte) (value & 0xFF));
return;
}
throw new IllegalArgumentException("Invalid size: " + size);
}
public static byte readLittleEndianInt8(ByteBuffer buffer, int offset) {
return buffer.get(buffer.position() + offset);
}
public static short readLittleEndianInt16(ByteBuffer buffer, int offset) {
return buffer.getShort(buffer.position() + offset);
}
public static int readByte(ByteBuffer buffer, int offset) {
return buffer.get(buffer.position() + offset) & 0xFF;
}
public static int readLittleEndianUnsigned(ByteBuffer buffer, int offset, int size) {
int base = buffer.position() + offset;
switch (size) {
case 4:View on GitHub (pinned to 86d9c8fc54)