{"record":{"id":"3aeb0f8eac28cf4e","repo":"flowable/flowable-engine","slug":"not-in-an-activity-or-process-definition-scope","errorCode":null,"errorMessage":"not in an activity- or process definition scope. (but in a transition scope)","messagePattern":"not in an activity- or process definition scope\\. \\(but in a transition scope\\)","errorType":"exception","errorClass":"PvmException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/pvm/ProcessDefinitionBuilder.java","lineNumber":150,"sourceCode":"    public ProcessDefinitionBuilder scope() {\n        getActivity().setScope(true);\n        return this;\n    }\n\n    public ProcessDefinitionBuilder executionListener(ExecutionListener executionListener) {\n        if (transition != null) {\n            transition.addExecutionListener(executionListener);\n        } else {\n            throw new PvmException(\"not in a transition scope\");\n        }\n        return this;\n    }\n\n    public ProcessDefinitionBuilder executionListener(String eventName, ExecutionListener executionListener) {\n        if (transition == null) {\n            scopeStack.peek().addExecutionListener(eventName, executionListener);\n        } else {\n            throw new PvmException(\"not in an activity- or process definition scope. (but in a transition scope)\");\n        }\n        return this;\n    }\n}\n","sourceCodeStart":132,"sourceCodeEnd":155,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/pvm/ProcessDefinitionBuilder.java#L132-L155","documentation":"PvmException thrown by the two-argument executionListener(eventName, listener) when the builder is currently in a transition scope. Event-named listeners can only be attached to activity or process-definition scopes, not transitions. This complements error 4742 which covers the reverse case.","triggerScenarios":"Calling executionListener(eventName, listener) immediately after startTransition(...) while 'transition' is still set.","commonSituations":"Fluent-builder misuse: adding an event-named listener right after opening a transition instead of before it or inside an activity scope.","solutions":["Attach the listener inside an activity or process scope: call executionListener(eventName, listener) right after startActivity(...) or at the top (process) level.","For transition-scoped listeners use the single-argument executionListener(listener) overload.","Move the call before the startTransition(...) invocation in the builder chain."],"exampleFix":"// before\nbuilder.startTransition(\"b\").executionListener(\"start\", myListener); // invalid in transition scope\n// after\nbuilder.startTransition(\"b\").executionListener(myListener);\n// or attach named listener at process/activity level:\nbuilder.executionListener(\"end\", myListener);","handlingStrategy":"validation","validationCode":"boolean inTransition = lastBuilderCallWasStartTransition;\nif (inTransition) {\n  throw new IllegalStateException(\"executionListener(eventName, listener) is invalid inside a transition scope\");\n}\nbuilder.executionListener(eventName, listener);","typeGuard":null,"tryCatchPattern":"try {\n  builder.executionListener(eventName, listener);\n} catch (PvmException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"transition scope\")) {\n    builder.executionListener(listener); // transition-scoped overload instead\n  }\n}","preventionTips":["Remember: transitions take the single-argument listener overload only.","Add event-named listeners at process or activity scope, before opening a transition."],"tags":["java","pvm","builder-scope","dsl-misuse"],"backgroundTag":"invalid-state-transition","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"}