{"record":{"id":"634d3db6eb18e437","repo":"hibernate/hibernate-orm","slug":"expecting-8-byte-values-to-construct-a-long","errorCode":null,"errorMessage":"Expecting 8 byte values to construct a long","messagePattern":"Expecting 8 byte values to construct a long","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/util/BytesHelper.java","lineNumber":117,"sourceCode":"\tpublic static long asLong(byte[] bytes) {\n\t\treturn asLong(bytes, 0);\n\t}\n\n\t/**\n\t * Interpret the binary representation of a long.\n\t *\n\t * @param bytes The bytes to interpret.\n\t * @param srcPos starting position in the source array.\n\t *\n\t * @return The long\n\t */\n\tpublic static long asLong(byte[] bytes, int srcPos) {\n\t\tif ( bytes == null ) {\n\t\t\treturn 0;\n\t\t}\n\t\tfinal int size = srcPos + 8;\n\t\tif ( bytes.length < size ) {\n\t\t\tthrow new IllegalArgumentException( \"Expecting 8 byte values to construct a long\" );\n\t\t}\n\t\tlong value = 0;\n\t\tfor (int i=srcPos; i<size; i++) {\n\t\t\tvalue = (value << 8) | (bytes[i] & 0xff);\n\t\t}\n\t\treturn value;\n\t}\n\n\tpublic static String toBinaryString(byte value) {\n\t\tString formatted = Integer.toBinaryString( value );\n\t\tif ( formatted.length() > 8 ) {\n\t\t\tformatted = formatted.substring( formatted.length() - 8 );\n\t\t}\n\t\tStringBuilder buf = new StringBuilder( \"00000000\" );\n\t\tbuf.replace( 8 - formatted.length(), 8, formatted );\n\t\treturn buf.toString();\n\t}\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/util/BytesHelper.java#L99-L135","documentation":"Error \"Expecting 8 byte values to construct a long\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/BytesHelper.java:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass exactly 8 bytes to asLong(); validate array length before conversion."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}