[jboss-jira] [JBoss JIRA] (JBRULES-3483) Off-by-one error in FullFastIterator.next() leads to botched queries
Adar Dembo (JIRA)
jira-events at lists.jboss.org
Wed Apr 25 20:31:18 EDT 2012
Adar Dembo created JBRULES-3483:
-----------------------------------
Summary: Off-by-one error in FullFastIterator.next() leads to botched queries
Key: JBRULES-3483
URL: https://issues.jboss.org/browse/JBRULES-3483
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-core
Affects Versions: 5.4.0.CR1
Reporter: Adar Dembo
Assignee: Mark Proctor
I'll reproduce the entirety of the method() below for clarity:
{code}
public Entry next(Entry object) {
RightTuple rightTuple = ( RightTuple ) object;
RightTupleList list = null;
if ( rightTuple != null ) {
list = rightTuple.getMemory(); // assumes you do not pass in a null RightTuple
}
int length = table.length;
while ( this.row < length ) {
// check if there is a current bucket
while ( list == null ) {
// iterate while there is no current bucket, trying each array position
list = (RightTupleList) this.table[this.row];
this.row++;
if ( list != null ) {
// we have a bucket so assign the frist LeftTuple and return
rightTuple = (RightTuple) list.getFirst( );
return rightTuple;
} else if ( this.row >= length ) {
// we've scanned the whole table and nothing is left, so return null
return null;
}
}
rightTuple = (RightTuple) rightTuple.getNext();
if ( rightTuple != null ) {
// we have a next tuple so return
return rightTuple;
} else {
list = (RightTupleList) list.getNext();
// try the next bucket if we have a shared array position
if ( list != null ) {
// if we have another bucket, assign the first RightTuple and return
rightTuple = (RightTuple) list.getFirst( );
return rightTuple;
}
}
}
return null;
}
{code}
The problem is when we have a RightTupleList in the last row of the table, and that list has more than one RightTuple. The call to next() that brings us to this list will increment this.row so that it's now equal to table.length. A subsequent next() should retrieve the next RightTuple, but because all of that code is conditioned on (table.row < length), the iteration ends prematurely. This affects one of my queries, which for an object with a particular hash code was only returning the first match instead of all of the matches.
I took a quick look at LeftTupleIndexHashTable.FullFastIterator, and since the code is identical, it's probably also broken.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list