Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding null guards against command contexts? #4553

Open
pingpingy1 opened this issue Jan 30, 2024 · 0 comments
Open

Adding null guards against command contexts? #4553

pingpingy1 opened this issue Jan 30, 2024 · 0 comments

Comments

@pingpingy1
Copy link

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:

  1. Might this be a common problem amongst others as well? Or is this too niche a critique to initiate a pull request?
  2. 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.

An example of such a case:

import org.activiti.engine.impl.bpmn.behavior.InclusiveGatewayActivityBehavior;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.IdentityLinkEntityImpl;

public class Test {
    public static void main(String args[]) throws Exception {
        InclusiveGatewayActivityBehavior behavior= new InclusiveGatewayActivityBehavior();
        IdentityLinkEntityImpl linkEntity = new IdentityLinkEntityImpl();
        ExecutionEntity executionEntity = linkEntity.getProcessInstance();
        behavior.executeInactive(executionEntity);
    }
}
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant