{"record":{"id":"7f2e05ab61678bb2","repo":"hibernate/hibernate-orm","slug":"the-byte-must-not-be-null","errorCode":null,"errorMessage":"The byte[] must not be null","messagePattern":"The byte\\[\\] must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/util/SerializationHelper.java","lineNumber":229,"sourceCode":"\t * Thread Context ClassLoader (TCCL). If there is no TCCL set,\n\t * the classloader of the calling class is used.\n\t * <p>\n\t * Delegates to {@link #deserialize(byte[], ClassLoader)}\n\t *\n\t * @param objectData the serialized object, must not be null\n\t *\n\t * @return the deserialized object\n\t *\n\t * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code>\n\t * @throws SerializationException (runtime) if the serialization fails\n\t */\n\tpublic static Object deserialize(byte[] objectData) throws SerializationException {\n\t\treturn doDeserialize( wrap( objectData ), defaultClassLoader(), hibernateClassLoader(), null );\n\t}\n\n\tprivate static InputStream wrap(byte[] objectData) {\n\t\tif ( objectData == null ) {\n\t\t\tthrow new IllegalArgumentException( \"The byte[] must not be null\" );\n\t\t}\n\t\treturn new ByteArrayInputStream( objectData );\n\t}\n\n\t/**\n\t * Deserializes an object from an array of bytes.\n\t * <p>\n\t * Delegates to {@link #deserialize(InputStream, ClassLoader)} using a\n\t * {@link ByteArrayInputStream} to wrap the array.\n\t *\n\t * @param objectData the serialized object, must not be null\n\t * @param loader The classloader to use\n\t *\n\t * @return the deserialized object\n\t *\n\t * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code>\n\t * @throws SerializationException (runtime) if the serialization fails\n\t */","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/util/SerializationHelper.java#L211-L247","documentation":"deserialize(byte[]) funnels through a private wrap(byte[]) helper that must turn the array into a ByteArrayInputStream; a null array fails fast there with IllegalArgumentException before any stream construction or classloading happens. This is a plain null-hostile argument contract on the byte-array convenience overload.","triggerScenarios":"Calling SerializationHelper.deserialize((byte[]) null) or deserialize(null, loader), typically because the blob fetch returned null (row absent, cache miss modeled as null) and the caller passed it through.","commonSituations":"Cache or repository methods that return null on miss, piped directly into deserialize; optional columns read as null from the database; tests using null placeholders.","solutions":["Null-check (and ideally emptiness-check) the byte array before calling deserialize and fail with a contextual message naming the source.","Model 'no data' explicitly (Optional.empty / null return) instead of routing null into deserialization."],"exampleFix":"// before\nbyte[] blob = rs.getBytes(\"payload\"); // null when column is NULL\nObject o = SerializationHelper.deserialize(blob); // IllegalArgumentException\n\n// after\nbyte[] blob = rs.getBytes(\"payload\");\nif (blob == null) return null; // column NULL -> no payload\nObject o = SerializationHelper.deserialize(blob);","handlingStrategy":"validation","validationCode":"if (objectData == null || objectData.length == 0) {\n    return null; // no payload stored\n}\nObject o = SerializationHelper.deserialize(objectData);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check byte arrays from database reads (NULL columns come back as null).","Use Optional or explicit null returns to model missing payloads instead of passing null on."],"tags":["hibernate","serialization","null-check","argument-validation"],"backgroundTag":"null-argument-contract-violation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}