I experienced this to be a possible error source in jbpm 3 already, so I absolutely agree with you!
we could do that, but i have some reservations:
if a client calls signal on an ended execution, there must be a bug in the client code. cause the process doesn't expect an external trigger any more.
so if you start protecting the users from his own mistakes, maybe we need to do it in a lot of other places as well ? guard conditions on transitions are already covered. but are there other ?
you can add some checks in some methods. but how far do you want to go ? do you want to include these checks in getters and setters ? including related runtime data objects like variables, bpel correlation sets, xpdl swimlane instances...
which methods would you like to guard with an already-ended-check like that ?
if a client calls signal on an ended execution, there must be a bug in the client code
I agree, but in circumstances, where I really trigger the execution, it should be checked. Not in getters and setters, only in signalling stuff (or ending TaskInstances, but I am not sure, how this is handled in PVM).
This matches with Design by contract I think, because the contract is to signal correctly, if it was not yet signaled. Otherwiese the client violates the contract, which should be indicated by an exception.
asserts would be a good choise here I think, that's what they made for. And that can even makes the code more readable...
If we just add to the 'end()' method:
node = null; transition = null;
throw new JbpmException("execution is not in a node or in a transition");when a ended execution is signaled.
If there is a bug in the client code, an exception is raised. There is no need to perform additional checks in other methods.
Is that solution ok ?
adding node = null; is not ok. there can be different end states in a process and the actual end state can matter.
if a check like that is introduced, it must be with a check on an isEnded property.
make sure that it can be bypassed by calling execution.setEnded(false); or something like that.