You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of Context.getCommandContext(), null is returned if commandContextThreadLocal has an empty stack.
While this is fair when only considering this method, in the broader context, the propagation of this null leads to difficult and convoluted debugging (often in the form of NullPointerExceptions).
Thus, I'd like to ask the following questions:
Might this be a common problem amongst others as well? Or is this too niche a critique to initiate a pull request?
If this is a problem worth addressing, what would be the best way to do so? Here are some of my thoughts:
In the aforementioned getCommandContext method, throw an exception (such as IllegalStateException) if the current stack is empty. I am wary of this solution as there may be situations where the null handling could be more suitable.
Add null guards whenever getCommandContext is called. While much more time-consuming than the previous option (and possibly more so than any time saved on future debugging anyways), this allows for a case-by-case implementation of the default behavior when the stack is empty.
While I am certainly willing to patch either way and open a PR, I wanted to get some approval or discussion before doing so.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.activiti.engine.impl.interceptor.CommandContext.getExecutionEntityManager()" because "commandContext" is null at org.activiti.engine.impl.bpmn.behavior.InclusiveGatewayActivityBehavior.executeInclusiveGatewayLogic(InclusiveGatewayActivityBehavior.java:66) at org.activiti.engine.impl.bpmn.behavior.InclusiveGatewayActivityBehavior.executeInactive(InclusiveGatewayActivityBehavior.java:61) at Test.main(Test.java:10)
The text was updated successfully, but these errors were encountered:
The current implementation of
Context.getCommandContext()
,null
is returned ifcommandContextThreadLocal
has an empty stack.While this is fair when only considering this method, in the broader context, the propagation of this
null
leads to difficult and convoluted debugging (often in the form ofNullPointerException
s).Thus, I'd like to ask the following questions:
getCommandContext
method, throw an exception (such asIllegalStateException
) if the current stack is empty. I am wary of this solution as there may be situations where thenull
handling could be more suitable.null
guards whenevergetCommandContext
is called. While much more time-consuming than the previous option (and possibly more so than any time saved on future debugging anyways), this allows for a case-by-case implementation of the default behavior when the stack is empty.While I am certainly willing to patch either way and open a PR, I wanted to get some approval or discussion before doing so.
An example of such a case:
The text was updated successfully, but these errors were encountered: