[
https://jira.jboss.org/jira/browse/JBRULES-1817?page=com.atlassian.jira.p...
]
Charles Daniels commented on JBRULES-1817:
------------------------------------------
I have created a patch for FactTemplateFieldExtractor in the 4.0.x branch (current version
in pom.xml is 4.0.8.SNAPSHOT) by backporting the hashCode() and equals(Object) methods
from the 5.0.0.24825.M5 branch. I don't have Jira permissions to attach the patch
file, so I have pasted it below. If someone could apply this patch so that it makes it
into the 4.0.8 release, it would be greatly appreciated. Thanks.
Index: FactTemplateFieldExtractor.java
===================================================================
--- FactTemplateFieldExtractor.java (revision 25004)
+++ FactTemplateFieldExtractor.java (working copy)
@@ -96,4 +96,31 @@
Object object) {
return ((Fact) object).getFieldValue( this.fieldIndex ) == null;
}
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((factTemplate == null) ? 0 :
factTemplate.hashCode());
+ result = prime * result + fieldIndex;
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ FactTemplateFieldExtractor other = (FactTemplateFieldExtractor) obj;
+
+ if ( factTemplate == null ) {
+ if ( other.factTemplate != null ) return false;
+ } else if ( !factTemplate.equals( other.factTemplate ) ) {
+ return false;
+ }
+
+ if ( fieldIndex != other.fieldIndex ) {
+ return false;
+ }
+ return true;
+ }
+
}
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
Fix For: 5.0.0.M5
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