[jdom-interest] Bug when iterating in reverse order over FilteredList

Bradley S. Huffman hip at cs.okstate.edu
Thu Jul 24 19:38:38 PDT 2003


Vadim Strizhevsky writes:

> 
> I think I was in my interpretation of the bug reason. I was able to fix
> it by changing the hasPrevious() function CREATE case not to substract 1
> from thine initialCursor. it works, but I'm not sure that's a right
> solution that covers all possible cases. Hopefully someone who is more
> familiar with this code can comment.

It sounds right, also initialCursor should never be greater than content size,
but just to be sure the moveBackward call should use content size just to be
safe.  Like you, it seems to work but I haven't had time to write unit tests
to give it a good workwout.

Brad 

*** ContentList.java	Thu Jul 24 11:55:57 2003
--- ContentList.new	Thu Jul 24 11:48:07 2003
***************
*** 1080,1088 ****
              checkConcurrentModification();
  
              switch(lastOperation) {
!             case CREATE:  cursor = initialCursor - 1;
!                           if (cursor >= ContentList.this.size()) {
!                                cursor = moveBackward(initialCursor - 1);
                            }
                            break;
              case PREV:
--- 1080,1089 ----
              checkConcurrentModification();
  
              switch(lastOperation) {
!             case CREATE:  cursor = initialCursor;
!                           int size = ContentList.this.size();
!                           if (cursor >= size) {
!                                cursor = moveBackward(size - 1);
                            }
                            break;
              case PREV:
***************
*** 1250,1256 ****
          }
  
          /**
!          * Returns index in the backing list by moving forward start + 1
           * objects that match our filter.
           */
          private int initializeCursor(int start) {
--- 1251,1257 ----
          }
  
          /**
!          * Returns index in the backing list by moving forward start
           * objects that match our filter.
           */
          private int initializeCursor(int start) {



More information about the jdom-interest mailing list