rulebook icon indicating copy to clipboard operation
rulebook copied to clipboard

Auditor not set on rules when RuleBookBuilder.create(Class) is used

Open danielmustafa opened this issue 5 years ago • 2 comments

Suppose I have a class

public class MyRuleBook extends CoRRuleBook {
    
    // some named rules here

}

And I want to reference that class in the RuleBookBuilder process:

RuleBookBuilder.create(MyRuleBook.class).asAuditor().build();

When I use the above statement, the rules inside of MyRuleBook do not get the Auditor value injected. So when I try to run the rules set I get an NPE in AuditableRule#invoke (Line 100) because it tries to update the RuleStatus but has no Auditor instance to update.

If I try to build a RuleBook using the RuleBookBuilder and use the addRule chained approach as described in the documentation, it works. Is this Auditor not available when we try to create a rulebook using a specific RuleBook class?

danielmustafa avatar Jan 13 '21 03:01 danielmustafa

Looking a bit deeper, I believe this is due to the fact that my class rulebook is extending CoRRuleBook, so when the rules are lazily added to the rulebook it is executing the CoRRuleBook#addRule instead of RuleBookAuditor#addRule. However my custom Rulebook does get decorated with RuleBookAuditor like I expect.

danielmustafa avatar Jan 14 '21 17:01 danielmustafa

I have the same problem and I couldn't fix it. Did you find a way to solve it ?

rocnwall avatar Dec 17 '21 18:12 rocnwall