Context.getCommandContext is a shorthand to access the command context at any place without passing it on. This requires the code to be executed within an active command, or else the method returns null.
To be precise, your code snippets are not equivalent because snippet 2 is not executed within a command. Given an active command, these are equivalent
I see … I found out that both behave the same when I use them inside a HistoryEventHandler. I guess thats because the handler itself is executed in a commandContext.
Has anyone found a way to use Context methods outside of a command without getting null? I want to use the DeploymentCache to get a process definition using the following snippet: