Uploaded image for project: 'JBRULES'
  2. JBRULES-3483

Off-by-one error in FullFastIterator.next() leads to botched queries



      I'll reproduce the entirety of the method() below for clarity:

              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];
                          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;

      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.

        Gliffy Diagrams




              • Assignee:
                mark.proctor Mark Proctor
                hltbdivl Adar Dembo
              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created: