[jboss-jira] [JBoss JIRA] Created: (JBRULES-1817) FactTemplateFieldExtractor must implement equals() method

Stephanie Kroll (JIRA) jira-events at lists.jboss.org
Tue Oct 21 16:08:20 EDT 2008


FactTemplateFieldExtractor must implement equals() method
---------------------------------------------------------

                 Key: JBRULES-1817
                 URL: https://jira.jboss.org/jira/browse/JBRULES-1817
             Project: JBoss Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: drools-core
    Affects Versions: 4.0.7
         Environment: Sun JDK1.5.0_12 on Windows XP
            Reporter: Stephanie Kroll
            Assignee: Mark Proctor


FactTemplateFieldExtractor does not implement equals().  This causes rules not to fire when the number of literal string equality constraints equals or exceeds the alpha node hashing threshold.

To reproduce for the trivial case, I created the following rule package:

package TestFactTemplate

template MyFact
	String stringVal;
end

rule "Rule1"
	when
	    MyFact (stringVal == "AA")
	then
		System.out.println("Rule1 fired");
end

rule "Rule2"
	when
	    MyFact (stringVal == "AA")
	then
		System.out.println("Rule2 fired");
end

I implemented the Fact interface and returned "AA" from the two getFieldValue() methods.  I also set the alphaNodeHashingThreshold to 2.  When executing the rules, only Rule2 fires.

If FactTemplateFieldExtractor implements equals() like so:

    public boolean equals(final Object object) {
        if ( this == object ) {
            return true;
        }
        if ( !(object instanceof FactTemplateFieldExtractor) ) {
            return false;
        }
        final FactTemplateFieldExtractor other = (FactTemplateFieldExtractor) object;
        return this.factTemplate.equals(other.factTemplate) && 
        	this.fieldIndex == other.fieldIndex;
    }

then both rules fire.

The problem arises because without the equals() method for the field extractor, the LiteralConstraints do not report as equal, and the network does not reuse the nodes in BuildUtils.attachNode.  When CompositeObjectSinkAdapter hashes the sinks because the threshold is met, only the last one is preserved in the hashedSinkMap since the HashKeys are the same.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list