{"record":{"id":"9259b30e4e2dfe40","repo":"flowable/flowable-engine","slug":"not-in-a-transition-scope","errorCode":null,"errorMessage":"not in a transition scope","messagePattern":"not 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":141,"sourceCode":"            transition.setDestination(destination);\n        }\n        return processDefinition;\n    }\n\n    protected ActivityImpl getActivity() {\n        return (ActivityImpl) scopeStack.peek();\n    }\n\n    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":123,"sourceCodeEnd":155,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/pvm/ProcessDefinitionBuilder.java#L123-L155","documentation":"PvmException thrown by the single-argument executionListener(...) when the builder is not currently inside a transition (the internal 'transition' cursor is null). Adding an execution listener with this overload only makes sense immediately after startTransition(...). It is a builder-state (scope) violation.","triggerScenarios":"Calling executionListener(listener) before any startTransition(...) call, or after a subsequent startActivity(...) call that changed the current scope.","commonSituations":"Builder DSL misuse: adding a transition-scoped listener at the wrong point in the fluent call chain, e.g. after switching back to an activity or process scope.","solutions":["Call this overload only directly after startTransition(...) and before starting another activity or transition.","Use the two-argument executionListener(eventName, listener) when you are in an activity or process scope.","Reorder the builder calls so the listener is added while the transition is the current element."],"exampleFix":"// before\nbuilder.startActivity(\"a\");\nbuilder.executionListener(myListener); // wrong scope\n// after\nbuilder.startActivity(\"a\").startTransition(\"b\").executionListener(myListener);","handlingStrategy":"validation","validationCode":"// only valid immediately after startTransition(...); track builder state yourself\nboolean inTransition = lastBuilderCallWasStartTransition;\nif (!inTransition) {\n  throw new IllegalStateException(\"executionListener(listener) requires an open transition scope\");\n}\nbuilder.executionListener(listener);","typeGuard":null,"tryCatchPattern":"try {\n  builder.executionListener(listener);\n} catch (PvmException e) {\n  throw new IllegalStateException(\"Call executionListener(listener) directly after startTransition()\", e);\n}","preventionTips":["Group transition-scoped DSL calls together in one chain starting with startTransition(...).","Never interleave startActivity(...) between startTransition(...) and its listeners.","Prefer the two-argument overload when unsure of the current scope."],"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"}