{"record":{"id":"de5404e13de63b8c","repo":"flowable/flowable-engine","slug":"user-is-null","errorCode":null,"errorMessage":"user is null","messagePattern":"user is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/SaveUserCmd.java","lineNumber":47,"sourceCode":" * @author Joram Barrez\n */\npublic class SaveUserCmd implements Command<Void>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    \n    protected IdmEngineConfiguration idmEngineConfiguration;\n    \n    protected User user;\n\n    public SaveUserCmd(User user, IdmEngineConfiguration idmEngineConfiguration) {\n        this.user = user;\n        this.idmEngineConfiguration = idmEngineConfiguration;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (user == null) {\n            throw new FlowableIllegalArgumentException(\"user is null\");\n        }\n        \n        if (idmEngineConfiguration.getUserEntityManager().isNewUser(user)) {\n            if (user.getPassword() != null) {\n                PasswordEncoder passwordEncoder = idmEngineConfiguration.getPasswordEncoder();\n                PasswordSalt passwordSalt = idmEngineConfiguration.getPasswordSalt();\n                user.setPassword(passwordEncoder.encode(user.getPassword(), passwordSalt));\n            }\n            \n            if (user instanceof UserEntity) {\n                idmEngineConfiguration.getUserEntityManager().insert((UserEntity) user, true);\n            } else {\n                CommandContextUtil.getDbSqlSession(commandContext).insert((Entity) user, idmEngineConfiguration.getIdGenerator());\n            }\n        } else {\n            UserEntity dbUser = idmEngineConfiguration.getUserEntityManager().findById(user.getId());\n            user.setPassword(dbUser.getPassword());\n            idmEngineConfiguration.getUserEntityManager().updateUser(user);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-idm-engine/src/main/java/org/flowable/idm/engine/impl/cmd/SaveUserCmd.java#L29-L65","documentation":"SaveUserCmd persists a User through the UserEntityManager; for new users it also hashes the password with the configured PasswordEncoder and salt. A null User cannot be inserted or updated, so the command throws FlowableIllegalArgumentException immediately.","triggerScenarios":"Calling identityService.saveUser(null) or executing new SaveUserCmd(config, null); also when the user reference comes from a failed lookup or an unbound process/task variable.","commonSituations":"Chain like saveUser(query().userId(id).singleResult()) when the user no longer exists; user objects built from unvalidated request bodies where the field is absent.","solutions":["Create the user first (identityService.newUser(id)) and set fields before saving","Verify the preceding lookup that returned the null user reference","Null-check before save; create or skip depending on business logic","Validate request/config payloads so the User object is always populated"],"exampleFix":"// before\nidentityService.saveUser(user);\n// after\nif (user == null) {\n    user = identityService.newUser(userId);\n    user.setPassword(rawPassword);\n}\nidentityService.saveUser(user);","handlingStrategy":"validation","validationCode":"if (user == null) throw new IllegalArgumentException(\"user must not be null\");","typeGuard":"boolean isSavableUser(User u) { return u != null && u.getId() != null && !u.getId().trim().isEmpty(); }","tryCatchPattern":"try { identityService.saveUser(user); } catch (FlowableIllegalArgumentException e) { log.error(\"Attempted to save null user\", e); }","preventionTips":["Create users via identityService.newUser(id) before saving","Never pass lookup results to saveUser without a null check","Validate API/DTO payloads map to a fully populated User"],"tags":["flowable","idm","null-argument","user"],"backgroundTag":"null-argument","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"}