{"record":{"id":"3ca9904dd2b0b5a9","repo":"flowable/flowable-engine","slug":"unexpected-exception-when-serializing-jpa-id-s-3ca990","errorCode":null,"errorMessage":"Unexpected exception when serializing JPA id's","messagePattern":"Unexpected exception when serializing JPA id's","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityListVariableType.java","lineNumber":154,"sourceCode":"\n            return result;\n        }\n        return null;\n    }\n\n    /**\n     * @return a bytearray containing all ID's in the given string serialized as an array.\n     */\n    protected byte[] serializeIds(List<String> ids) {\n        try {\n            String[] toStore = ids.toArray(new String[]{});\n            ByteArrayOutputStream baos = new ByteArrayOutputStream();\n            ObjectOutputStream out = new ObjectOutputStream(baos);\n\n            out.writeObject(toStore);\n            return baos.toByteArray();\n        } catch (IOException ioe) {\n            throw new ActivitiException(\"Unexpected exception when serializing JPA id's\", ioe);\n        }\n    }\n\n    protected String[] deserializeIds(byte[] bytes) {\n        try {\n            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);\n            ObjectInputStream in = new ObjectInputStream(bais);\n\n            Object read = in.readObject();\n            if (!(read instanceof String[])) {\n                throw new ActivitiIllegalArgumentException(\"Deserialized value is not an array of ID's: \" + read);\n            }\n\n            return (String[]) read;\n        } catch (IOException ioe) {\n            throw new ActivitiException(\"Unexpected exception when deserializing JPA id's\", ioe);\n        } catch (ClassNotFoundException e) {\n            throw new ActivitiException(\"Unexpected exception when deserializing JPA id's\", e);","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityListVariableType.java#L136-L172","documentation":"Thrown by JPAEntityListVariableType.serializeIds() when Java object serialization of the String[] of entity IDs fails with IOException. The engine serializes the collected entity primary keys to bytes for the variable table; any stream/serialization failure is wrapped in ActivitiException.","triggerScenarios":"IOException on ObjectOutputStream.writeObject of the String[] ids (e.g. underlying ByteArrayOutputStream issues are rare; usually caused by custom objects in a overridden toStore array or IO infrastructure failure).","commonSituations":"Custom subclasses overriding id extraction so the array contains non-serializable elements; environment-level IO problems; JVM-level serialization incompatibility after changing the stored type.","solutions":["Inspect the chained IOException for the actual serialization failure","Ensure only String[] of IDs is passed to serialization (do not store raw entities in the id array)","Confirm element classes are Serializable if the stored structure was customized","Avoid modifying the serialization format between engine versions without variable migration"],"exampleFix":"// before\nout.writeObject(rawEntities); // non-serializable entities\n// after\nout.writeString(idStrings); // String[] of entity primary keys","handlingStrategy":"try-catch","validationCode":"// ids are Strings by design; verify before serialization\nboolean allStrings = java.util.Arrays.stream(ids).allMatch(Objects::nonNull);","typeGuard":"boolean isSerializableStringArray(Object ids) {\n    return ids instanceof String[] && java.util.Arrays.stream((String[]) ids).allMatch(Objects::nonNull);\n}","tryCatchPattern":"try {\n    runtimeService.setVariable(executionId, \"orders\", orderList);\n} catch (ActivitiException e) {\n    if (e.getCause() instanceof IOException) {\n        logger.error(\"JPA id serialization failed\", e.getCause());\n    }\n    throw e;\n}","preventionTips":["Do not subclass and put non-serializable objects into the id store","Keep id extraction producing plain String arrays","Pin engine serialization behavior across upgrade windows"],"tags":["jpa","serialization","variables","activiti"],"backgroundTag":"json-marshal-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}