{"record":{"id":"8f1a46be4fbb6c1c","repo":"alibaba/spring-ai-alibaba","slug":"bytes-cannot-be-empty","errorCode":null,"errorMessage":"bytes cannot be empty","messagePattern":"bytes cannot be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/serializer/Serializer.java","lineNumber":51,"sourceCode":"\n\tdefault String contentType() {\n\t\treturn \"application/octet-stream\";\n\t}\n\n\tdefault byte[] objectToBytes(T object) throws IOException {\n\t\tObjects.requireNonNull(object, \"object cannot be null\");\n\t\ttry (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {\n\t\t\tObjectOutputStream oas = new ObjectOutputStream(stream);\n\t\t\twrite(object, oas);\n\t\t\toas.flush();\n\t\t\treturn stream.toByteArray();\n\t\t}\n\t}\n\n\tdefault T bytesToObject(byte[] bytes) throws IOException, ClassNotFoundException {\n\t\tObjects.requireNonNull(bytes, \"bytes cannot be null\");\n\t\tif (bytes.length == 0) {\n\t\t\tthrow new IllegalArgumentException(\"bytes cannot be empty\");\n\t\t}\n\t\ttry (ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) {\n\t\t\tObjectInputStream ois = new ObjectInputStream(stream);\n\t\t\treturn read(ois);\n\t\t}\n\t}\n\n\t@Deprecated(forRemoval = true)\n\tdefault byte[] writeObject(T object) throws IOException {\n\t\treturn objectToBytes(object);\n\t}\n\n\t@Deprecated(forRemoval = true)\n\tdefault T readObject(byte[] bytes) throws IOException, ClassNotFoundException {\n\t\treturn bytesToObject(bytes);\n\t}\n\n\tdefault T cloneObject(T object) throws IOException, ClassNotFoundException {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/serializer/Serializer.java#L33-L69","documentation":"Serializer.bytesToObject validates the input byte array before deserializing: it throws NullPointerException for null bytes and IllegalArgumentException(\"bytes cannot be empty\") for a zero-length array, since ObjectInputStream requires at least a stream header to read from.","triggerScenarios":"Calling bytesToObject (directly or via readObject) with an empty byte[] — e.g. a persisted snapshot/checkpoint that was saved as an empty array, a truncated DB/blob column, or code that serializes to bytes but stores nothing.","commonSituations":"Corrupt or empty checkpoint rows in PostgreSQL/Redis/file persistence; migration writing default empty blobs; passing a newly-allocated but never-filled buffer.","solutions":["Check byte[] != null && bytes.length > 0 before calling bytesToObject","Fix the persistence layer to write a valid serialized payload instead of an empty array","Delete/repair the corrupt checkpoint record so the graph can re-initialize state","Verify serialization on write (serialize-then-deserialize round-trip) to catch empty payloads early"],"exampleFix":"// before\nT obj = serializer.bytesToObject(bytes);\n// after\nif (bytes == null || bytes.length == 0) {\n    return defaultState();\n}\nT obj = serializer.bytesToObject(bytes);","handlingStrategy":"validation","validationCode":"if (bytes == null || bytes.length == 0) {\n    throw new IllegalArgumentException(\"cannot deserialize empty checkpoint payload\");\n}","typeGuard":"boolean isNonEmptyPayload(byte[] b) {\n    return b != null && b.length > 0;\n}","tryCatchPattern":"try {\n    return serializer.bytesToObject(bytes);\n} catch (IllegalArgumentException e) {\n    if (\"bytes cannot be empty\".equals(e.getMessage())) {\n        return defaultState(); // rebuild instead of failing\n    }\n    throw e;\n} catch (IOException | ClassNotFoundException e) {\n    throw new IllegalStateException(\"corrupt payload\", e);\n}","preventionTips":["Always validate payload length before deserialization","Add a serialize->deserialize round-trip test for checkpoint save/load","Monitor persistence layers for empty blobs/rows","Fail fast on write if the serializer produced zero bytes"],"tags":["deserialization","empty-input","serialization","checkpoint"],"backgroundTag":"empty-required-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}