microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.47k stars 528 forks source link

Using OnSuccess/OnFailure Actions within a rule causes a NullReferenceException when the Context is not defined #576

Open williamb1024 opened 5 months ago

williamb1024 commented 5 months ago

If a rule's OnSuccess or OnFailure action's Context is not defined (resulting in a null value), during execution of the rule's action a NullReferenceException is thrown during the construction of the ActionContext instance.

While the builtin Actions require Context information, it is possible that a custom action would not. The action itself should be responsible for handling context information that is missing by detecting missing items within the context dictionary. The action's code should determine if an exception is the proper response.

https://github.com/microsoft/RulesEngine/blob/dc5298989583954cd6aac598267747b4ce635f45/src/RulesEngine/Actions/ActionContext.cs#L19

Checking context for null or using a null-coalescing operator would solve this issue.