{"record":{"id":"1c2b5449667a001f","repo":"apache/iceberg","slug":"could-not-deserialize-the-writeresult-object-1c2b54","errorCode":null,"errorMessage":"Could not deserialize the WriteResult object","messagePattern":"Could not deserialize the WriteResult object","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/sink/WriteResultSerializer.java","lineNumber":58,"sourceCode":"  public byte[] serialize(WriteResult writeResult) throws IOException {\n    ByteArrayOutputStream out = new ByteArrayOutputStream();\n    DataOutputViewStreamWrapper view = new DataOutputViewStreamWrapper(out);\n    byte[] result = InstantiationUtil.serializeObject(writeResult);\n    view.write(result);\n    return out.toByteArray();\n  }\n\n  @Override\n  public WriteResult deserialize(int version, byte[] serialized) throws IOException {\n    if (version == 1) {\n      DataInputDeserializer view = new DataInputDeserializer(serialized);\n      byte[] resultBuf = new byte[serialized.length];\n      view.read(resultBuf);\n      try {\n        return InstantiationUtil.deserializeObject(\n            resultBuf, IcebergCommittableSerializer.class.getClassLoader());\n      } catch (ClassNotFoundException cnc) {\n        throw new IOException(\"Could not deserialize the WriteResult object\", cnc);\n      }\n    }\n    throw new IOException(\"Unrecognized version or corrupt state: \" + version);\n  }\n}\n","sourceCodeStart":40,"sourceCodeEnd":64,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/sink/WriteResultSerializer.java#L40-L64","documentation":"WriteResultSerializer.deserialize wraps ClassNotFoundException from InstantiationUtil.deserializeObject into this IOException. The WriteResult bytes are valid enough to read, but the WriteResult class (or a nested class) cannot be loaded in the current JVM — a classpath/version mismatch when restoring state.","triggerScenarios":"Restoring a Flink checkpoint/savepoint whose WriteResult state was written with a different Iceberg version whose WriteResult class isn't loadable (missing iceberg-flink-runtime jar on TaskManagers, shaded duplicate classes, or version downgrade).","commonSituations":"Job jar shading Iceberg differently than the runtime; TaskManager classpath missing the iceberg jars after a cluster upgrade; resuming state across incompatible Iceberg releases.","solutions":["Ensure the exact iceberg-flink-runtime version that wrote the state is on the classpath of JobManager and TaskManagers.","Fix shading conflicts: mark Iceberg dependencies provided in the job jar so the cluster's version is used consistently.","Resume from a savepoint produced by the current version (stop-with-savepoint --drain) instead of old state.","If using Flink's classloader options, set classloader.check-leaked-classloader / child-first consistently across versions."],"exampleFix":"// before (pom.xml)\n<dependency>org.apache.iceberg:iceberg-flink-runtime-1.19:compile</dependency>\n// after\n<dependency>\n  <groupId>org.apache.iceberg</groupId>\n  <artifactId>iceberg-flink-runtime-1.19</artifactId>\n  <scope>provided</scope>\n</dependency>","handlingStrategy":"type-guard","validationCode":"// verify WriteResult is loadable on the cluster classpath before resuming\ntry {\n  Class.forName(\"org.apache.iceberg.flink.sink.WriteResult\");\n} catch (ClassNotFoundException e) {\n  throw new IllegalStateException(\"iceberg-flink runtime jar missing from classpath\", e);\n}","typeGuard":"static boolean writeResultLoadable() {\n  try {\n    WriteResultSerializer.class.getClassLoader().loadClass(\"org.apache.iceberg.flink.sink.WriteResult\");\n    return true;\n  } catch (ClassNotFoundException e) {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  env.execute();\n} catch (Exception e) {\n  Throwable root = ExceptionUtils.findThrowable(e, ClassNotFoundException.class).orElse(null);\n  if (root != null && root.getName().contains(\"WriteResult\")) {\n    // fix runtime jar/shading, then resubmit\n  }\n  throw e;\n}","preventionTips":["Mark Iceberg dependencies as provided so job and cluster use one version.","Deploy the exact iceberg-flink-runtime jar the state was written with.","Test savepoint restore in staging after every version bump."],"tags":["flink","serialization","classpath","checkpoint"],"backgroundTag":"class-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}