hibernate/hibernate-orm · error · IllegalArgumentException
Expecting 8 byte values to construct a long
Error message
Expecting 8 byte values to construct a long
What it means
Error "Expecting 8 byte values to construct a long" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/BytesHelper.java:117
public static long asLong(byte[] bytes) {
return asLong(bytes, 0);
}
/**
* Interpret the binary representation of a long.
*
* @param bytes The bytes to interpret.
* @param srcPos starting position in the source array.
*
* @return The long
*/
public static long asLong(byte[] bytes, int srcPos) {
if ( bytes == null ) {
return 0;
}
final int size = srcPos + 8;
if ( bytes.length < size ) {
throw new IllegalArgumentException( "Expecting 8 byte values to construct a long" );
}
long value = 0;
for (int i=srcPos; i<size; i++) {
value = (value << 8) | (bytes[i] & 0xff);
}
return value;
}
public static String toBinaryString(byte value) {
String formatted = Integer.toBinaryString( value );
if ( formatted.length() > 8 ) {
formatted = formatted.substring( formatted.length() - 8 );
}
StringBuilder buf = new StringBuilder( "00000000" );
buf.replace( 8 - formatted.length(), 8, formatted );
return buf.toString();
}
View on GitHub (pinned to fad1729dce)
Solutions
- Pass exactly 8 bytes to asLong(); validate array length before conversion.
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/BytesHelper.java:117 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/634d3db6eb18e437.
Report an issue: GitHub.