[rules-dev] When a rule equals a rule

Wolfgang Laun wolfgang.laun at gmail.com
Fri Mar 22 14:45:26 EDT 2013


There was this thread about comparing compiled and serialized
packages. Somewhat interested, I decided to run a few tests. (Now I
know that the IdentityHashMap used in there somewhere dooms all
efforts.)

It is possible to detect the addition or removal of rules by comparing
the rules contained in the KnowledgePackages, using
KnowledgePackage.getRules() and by keeping track of the rules
identified by names. Good.

Then I used org.drools.definition.rule.Rule's method equals(), but
this returns stubbornly true, even when rules actually differ. I
thought that this was due to org.drools.definition.rule.Rule's
implementation (in org.drools.definitions.rule.impl.RuleImpl) just
being a "shadow" object, hiding the hot stuff that's kept in an
org.drools.rule.Rule object.

But changing something that *is* exposed - namely the rule's metadata
- still didn't make equals() false.

So I looked at
org.drools.definitions.rule.impl.RuleImpl.equals(), and was quite
astonished to see that this one does call the equals() of the real
McCoy, i.e., org.drools.rule.Rule.equals(). Looking at this method
made it clear to me that this method isn't good for comparing rules
beyond the scope of a single knowledge base or knowledge builder: it
is firmly rooted in the assumption that rule name and the rule's
package name are "The Rule".

-W


More information about the rules-dev mailing list