{"record":{"id":"c854f9748f509665","repo":"flowable/flowable-engine","slug":"null-value-cannot-be-saved","errorCode":null,"errorMessage":"null value cannot be saved","messagePattern":"null value cannot be saved","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/JPAEntityMappings.java","lineNumber":69,"sourceCode":"    }\n\n    public EntityMetaData getEntityMetaData(Class<?> clazz) {\n        EntityMetaData metaData = classMetaDatamap.get(clazz.getName());\n        if (metaData == null) {\n            // Class not present in meta-data map, create metaData for it and add\n            metaData = scanClass(clazz);\n            classMetaDatamap.put(clazz.getName(), metaData);\n        }\n        return metaData;\n    }\n\n    private EntityMetaData scanClass(Class<?> clazz) {\n        return enitityScanner.scanClass(clazz);\n    }\n\n    public String getJPAClassString(Object value) {\n        if (value == null) {\n            throw new FlowableIllegalArgumentException(\"null value cannot be saved\");\n        }\n\n        EntityMetaData metaData = getEntityMetaData(value.getClass());\n        if (!metaData.isJPAEntity()) {\n            throw new FlowableIllegalArgumentException(\"Object is not a JPA Entity: class='\" + value.getClass() + \"', \" + value);\n        }\n\n        // Extract the class from the Entity instance\n        return metaData.getEntityClass().getName();\n    }\n\n    public String getJPAIdString(Object value) {\n        EntityMetaData metaData = getEntityMetaData(value.getClass());\n        if (!metaData.isJPAEntity()) {\n            throw new FlowableIllegalArgumentException(\"Object is not a JPA Entity: class='\" + value.getClass() + \"', \" + value);\n        }\n        Object idValue = getIdValue(value, metaData);\n        return getIdString(idValue);","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/JPAEntityMappings.java#L51-L87","documentation":"JPAEntityMappings.getJPAClassString maps a variable value to its entity class name for persistence. A null value cannot be mapped, so it throws FlowableIllegalArgumentException('null value cannot be saved').","triggerScenarios":"Calling getJPAClassString(null), typically via setValue on a JPA variable type path that doesn't pre-filter nulls, e.g. saving a variable whose value is null through a code path expecting an entity.","commonSituations":"Passing null entities from process/service code into setVariable with an explicitly chosen JPA type; form/task data binding supplying null; DAO returning null and result being stored directly.","solutions":["Guard for null before storing: if the entity is null, either skip the setVariable call or pass a type that handles null","Use a type-agnostic setVariable so Flowable's NullVariableType handles null","Ensure upstream code (forms, services) never yields null for required entity variables"],"exampleFix":"// before\nCustomer c = customerDao.find(id);\nruntimeService.setVariable(executionId, \"customer\", c); // c may be null\n// after\nCustomer c = customerDao.find(id);\nif (c != null) {\n    runtimeService.setVariable(executionId, \"customer\", c);\n} else {\n    runtimeService.setVariable(executionId, \"customer\", null); // handled by NullVariableType\n}","handlingStrategy":"validation","validationCode":"if (value == null) {\n    // don't route null through JPA variable type\n    runtimeService.setVariable(executionId, \"customer\", null);\n} else {\n    runtimeService.setVariable(executionId, \"customer\", value);\n}","typeGuard":"boolean isNonNullEntity(Object v) { return v != null; }","tryCatchPattern":null,"preventionTips":["Null-check DAO results before storing as variables","Let Flowable pick NullVariableType automatically for null values (no explicit JPA type)","Make entity variables optional-aware in forms and service tasks"],"tags":["jpa","null","validation","flowable"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}