{"record":{"id":"0412f41f47122eb6","repo":"apache/flink","slug":"error-during-java-deserialization","errorCode":null,"errorMessage":"Error during Java deserialization.","messagePattern":"Error during Java deserialization\\.","errorType":"exception","errorClass":"KryoException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/kryo/JavaSerializer.java","lineNumber":82,"sourceCode":"        }\n    }\n\n    @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n    @Override\n    public T read(Kryo kryo, Input input, Class aClass) {\n        try {\n            ObjectMap graphContext = kryo.getGraphContext();\n            ObjectInputStream objectStream = (ObjectInputStream) graphContext.get(this);\n            if (objectStream == null) {\n                // make sure we use Kryo's classloader\n                objectStream =\n                        new InstantiationUtil.ClassLoaderObjectInputStream(\n                                input, kryo.getClassLoader());\n                graphContext.put(this, objectStream);\n            }\n            return (T) objectStream.readObject();\n        } catch (Exception ex) {\n            throw new KryoException(\"Error during Java deserialization.\", ex);\n        }\n    }\n}\n","sourceCodeStart":64,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/kryo/JavaSerializer.java#L64-L86","documentation":"JavaSerializer.read() is the deserialization half of the Kryo-to-Java serialization bridge. It lazily builds an InstantiationUtil.ClassLoaderObjectInputStream over Kryo's Input (using Kryo's classloader) and calls readObject(). Any failure — class not found under the user classloader, serialVersionUID mismatch, stream corruption, or a readObject method throwing — is rethrown as KryoException 'Error during Java deserialization.'.","triggerScenarios":"Restoring a checkpoint/savepoint where a serialized class was renamed, moved packages, or its serialVersionUID changed; the user code classloader on the TaskManager not containing the class; corrupted or truncated buffer being handed to the input stream; a custom readObject implementation throwing.","commonSituations":"Job upgrade without a stable serialVersionUID; classes loaded from user jars absent from the TaskManager classpath; reading state written by a different Flink or class version; network buffer truncation producing a corrupted ObjectInputStream stream.","solutions":["Check the nested cause: ClassNotFoundException means the class is missing from the job's user-code jar — ship it and resubmit.","Add 'private static final long serialVersionUID = 1L;' to all classes stored in Java-serialized state so refactorings do not break compatibility.","If the class legitimately changed incompatibly, use state processor API / savepoint migration to rewrite state, or keep a compatible readObject path.","For corruption issues, verify the same serializer configuration (registered types/order) is used on write and read."],"exampleFix":"// before\npublic class Event { /* no serialVersionUID */ }\n\n// after\npublic class Event implements java.io.Serializable {\n    private static final long serialVersionUID = 1L;\n    // ...\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    T value = kryo.readObject(input, clazz);\n} catch (com.esotericsoftware.kryo.KryoException e) {\n    if (e.getCause() instanceof ClassNotFoundException) {\n        // missing class in user classloader: fail with class name\n    } else if (e.getCause() instanceof java.io.InvalidClassException) {\n        // serialVersionUID mismatch: needs state migration\n    }\n    throw e;\n}","preventionTips":["Declare explicit serialVersionUID on every class stored in serialized state.","Run a canary restore of savepoints in CI after class changes.","Keep user-code jars self-contained so the TaskManager classloader can resolve all stored classes."],"tags":["serialization","kryo","deserialization","state-migration","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}