{"record":{"id":"98a25a6ba9d3d30d","repo":"flowable/flowable-engine","slug":"processinstanceid-is-null-98a25a","errorCode":null,"errorMessage":"processInstanceId is null","messagePattern":"processInstanceId is null","errorType":"exception","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessInstanceNameCmd.java","lineNumber":40,"sourceCode":"import org.activiti.engine.impl.persistence.entity.ExecutionEntity;\nimport org.activiti.engine.runtime.ProcessInstance;\n\npublic class SetProcessInstanceNameCmd implements Command<Void>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    protected String processInstanceId;\n    protected String name;\n\n    public SetProcessInstanceNameCmd(String processInstanceId, String name) {\n        this.processInstanceId = processInstanceId;\n        this.name = name;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (processInstanceId == null) {\n            throw new ActivitiIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        ExecutionEntity execution = commandContext\n                .getExecutionEntityManager()\n                .findExecutionById(processInstanceId);\n\n        if (execution == null) {\n            throw new ActivitiObjectNotFoundException(\"process instance \" + processInstanceId + \" doesn't exist\", ProcessInstance.class);\n        }\n\n        if (!execution.isProcessInstanceType()) {\n            throw new ActivitiObjectNotFoundException(\"process instance \" + processInstanceId +\n                    \" doesn't exist, the given ID references an execution, though\", ProcessInstance.class);\n        }\n\n        if (execution.isSuspended()) {\n            throw new ActivitiException(\"process instance \" + processInstanceId + \" is suspended, cannot set name\");\n        }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessInstanceNameCmd.java#L22-L58","documentation":"SetProcessInstanceNameCmd.execute() performs its own null check and throws ActivitiIllegalArgumentException with the literal message 'processInstanceId is null' when the constructor was given a null id (this command, unlike the others, permits constructing it with null and fails only at execution time).","triggerScenarios":"managementService.setProcessInstanceName(null, name) or new SetProcessInstanceNameCmd(null, name).execute(...) — the id field was null because it came from an unpopulated bean, optional, or map lookup.","commonSituations":"Chained calls where an earlier query returned null (singleResult() on a miss) and its id was passed on; reflection-driven invocation with missing parameters.","solutions":["Guard the id before calling: only invoke setProcessInstanceName when the id is non-null.","Resolve the id via createProcessInstanceQuery().singleResult() and check for null first.","Note the difference from sibling commands: this one validates in execute(), so also wrap execution in try-catch for ActivitiIllegalArgumentException."],"exampleFix":"// before\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(bk).singleResult();\nmanagementService.setProcessInstanceName(pi.getId(), name); // pi may be null\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(bk).singleResult();\nif (pi != null) {\n    managementService.setProcessInstanceName(pi.getId(), name);\n}","handlingStrategy":"type-guard","validationCode":"if (pi == null || pi.getId() == null) {\n    throw new IllegalStateException(\"No running instance to rename\");\n}","typeGuard":"boolean canRename(ProcessInstance pi) { return pi != null && pi.getId() != null; }","tryCatchPattern":"try {\n    managementService.setProcessInstanceName(pid, name);\n} catch (org.activiti.engine.ActivitiIllegalArgumentException e) {\n    if (\"processInstanceId is null\".equals(e.getMessage())) {\n        // id was never provided; fix upstream lookup\n    }\n}","preventionTips":["Check singleResult() for null before reading getId()","Remember this command validates at execute() time, not construction — always guard before invoking"],"tags":["java","flowable","argument-validation","null"],"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"}