{"record":{"id":"969b68c63a9ef2ea","repo":"apache/iceberg","slug":"invalid-size-size","errorCode":null,"errorMessage":"Invalid size: + size","messagePattern":"Invalid size: \\+ size","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/util/ByteBuffers.java","lineNumber":100,"sourceCode":"  public static void writeLittleEndianUnsigned(ByteBuffer buffer, int value, int offset, int size) {\n    int base = buffer.position() + offset;\n    switch (size) {\n      case 4:\n        buffer.putInt(base, value);\n        return;\n      case 3:\n        buffer.putShort(base, (short) (value & 0xFFFF));\n        buffer.put(base + 2, (byte) ((value >> 16) & 0xFF));\n        return;\n      case 2:\n        buffer.putShort(base, (short) (value & 0xFFFF));\n        return;\n      case 1:\n        buffer.put(base, (byte) (value & 0xFF));\n        return;\n    }\n\n    throw new IllegalArgumentException(\"Invalid size: \" + size);\n  }\n\n  public static byte readLittleEndianInt8(ByteBuffer buffer, int offset) {\n    return buffer.get(buffer.position() + offset);\n  }\n\n  public static short readLittleEndianInt16(ByteBuffer buffer, int offset) {\n    return buffer.getShort(buffer.position() + offset);\n  }\n\n  public static int readByte(ByteBuffer buffer, int offset) {\n    return buffer.get(buffer.position() + offset) & 0xFF;\n  }\n\n  public static int readLittleEndianUnsigned(ByteBuffer buffer, int offset, int size) {\n    int base = buffer.position() + offset;\n    switch (size) {\n      case 4:","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/util/ByteBuffers.java#L82-L118","documentation":"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.","triggerScenarios":"Calling ByteBuffers.writeLittleEndianUnsigned(buffer, value, offset, size) with size of 0, 5, 8, negative, or any value outside {1,2,3,4}.","commonSituations":"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.","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"],"exampleFix":"// before\nByteBuffers.writeLittleEndianUnsigned(buf, value, offset, 8);\n// after\nByteBuffers.writeLittleEndianUnsigned(buf, value, offset, 4); // int max 4 bytes","handlingStrategy":"validation","validationCode":"if (size < 1 || size > 4) { throw new IllegalArgumentException(\"writeLittleEndianUnsigned size must be 1-4, got \" + size); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["java","bytebuffer","binary-encoding","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}