{"record":{"id":"8ce6305401e638d3","repo":"flowable/flowable-engine","slug":"variable","errorCode":null,"errorMessage":"Variable '","messagePattern":"Variable '","errorType":"http","errorClass":"FlowableException","httpStatus":500,"severity":"error","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableBaseResource.java","lineNumber":226,"sourceCode":"\n        // Figure out scope, revert to local is omitted\n        RestVariableScope scope = restVariable.getVariableScope();\n        if (scope == null) {\n            scope = RestVariableScope.LOCAL;\n        }\n\n        Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);\n        setVariable(task, restVariable.getName(), actualVariableValue, scope, isNew);\n\n        return getVariableFromRequestWithoutAccessCheck(task, restVariable.getName(), scope, false);\n    }\n\n    protected void setVariable(Task task, String name, Object value, RestVariableScope scope, boolean isNew) {\n        // Create can only be done on new variables. Existing variables should\n        // be updated using PUT\n        boolean hasVariable = hasVariableOnScope(task, name, scope);\n        if (isNew && hasVariable) {\n            throw new FlowableException(\"Variable '\" + name + \"' is already present on task '\" + task.getId() + \"'.\");\n        }\n\n        if (!isNew && !hasVariable) {\n            throw new FlowableObjectNotFoundException(\"Task '\" + task.getId() + \"' doesn't have a variable with name: '\" + name + \"'.\", null);\n        }\n\n        if (restApiInterceptor != null) {\n            if (isNew) {\n                restApiInterceptor.createTaskVariables(task, Collections.singletonMap(name, value), scope);\n            } else {\n                restApiInterceptor.updateTaskVariables(task, Collections.singletonMap(name, value), scope);\n            }\n        }\n\n        if (scope == RestVariableScope.LOCAL) {\n            taskService.setVariableLocal(task.getId(), name, value);\n        } else {\n            if (ScopeTypes.CMMN.equals(task.getScopeType()) && task.getScopeId() != null) {","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableBaseResource.java#L208-L244","documentation":"FlowableException thrown in setVariable when creating a new variable (POST, isNew=true) for a name that already exists on the task in the requested scope. Variables must be created once; existing variables must be updated via PUT. The full message includes the variable name and task id.","triggerScenarios":"POST /cmmn-runtime/tasks/{taskId}/variables with a variable whose name already exists on that task (local or global scope), instead of PUT /cmmn-runtime/tasks/{taskId}/variables/{name}.","commonSituations":"Re-running idempotency-broken client scripts; double submission of the same creation request; confusion between POST (create) and PUT (update) semantics.","solutions":["Use PUT to update an existing variable instead of POST","Check existence first via GET /tasks/{id}/variables/{name}","Make client scripts idempotent by using PUT or upsert logic","Delete the variable first if recreation is intended"],"exampleFix":"// before: re-POST existing variable\nPOST /cmmn-runtime/tasks/123/variables [{\"name\":\"status\",\"value\":\"x\"}]\n// after\nPUT /cmmn-runtime/tasks/123/variables/status {\"value\":\"x\"}","handlingStrategy":"validation","validationCode":"const existing = await getTaskVariable(taskId, name).catch(() => null);\nif (existing) throw new Error(`variable '${name}' already exists on task ${taskId}; use PUT`);","typeGuard":null,"tryCatchPattern":"try { await postVariable(v) } catch (e) { if (/is already present on task/.test(e.message)) return putVariable(v); throw e; }","preventionTips":["Treat POST as create-only, PUT as update-only","Make client scripts idempotent (upsert or existence check)","Avoid re-running failed batch scripts without checking state"],"tags":["rest","conflict","variables"],"backgroundTag":"file-already-exists","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"}