RegisterSearchFAQ UsergroupsLog in
IndexOutOfBoundsException

 
Reply to topic    Citra Technologies Forum Index » Report a Bug View previous topic
View next topic

IndexOutOfBoundsException
Author Message
cone



Joined: 29 May 2007
Posts: 322

Post IndexOutOfBoundsException Reply with quote
Hi,

over 8 years we use an extended abstractTableModel which implements the ListTableModel.

Now i want to use the citraTable 4.9 and one of our customers get an IndexOutOfBoundsException.
Some tables work others not...
I searched a lot and finally i found the problem.

SortTableModel.sortedIndexes size = 0 but there are rows?!

Under some circumstances the error occure:
* start with 0 rows
* set sort for on ecolumn
* no filtering! if filtering is enabled then there were no error
* only implement ListTableModel (as described in the manual)

Now i implement ReorderModel and it works fine.

It would be nice to get some information when things that work before never do it again Sad
At least you can update the manual with a warning.

cheers, michael
Wed May 10, 2017 5:51 am View user's profile Send private message
cone



Joined: 29 May 2007
Posts: 322

Post Reply with quote
Well, i thought a had a solution and now more/other problems occure.

In the days before Version 4.9 with an extended AbstractTableModel which implements ListTableModel one can setRows (until now it was not neccessary to implement ReorderModel) and the selection still remains.
Now with
Code:

      int[] i = new int[oldRowSize];
      Arrays.fill(i, -1);
      fireRowsMapped(i);


The selection is cleared Sad

cheers, michael
Thu May 11, 2017 1:50 am View user's profile Send private message
support



Joined: 21 Feb 2006
Posts: 1443

Post Re: IndexOutOfBoundsException Reply with quote
cone wrote:

Now i implement ReorderModel and it works fine.

It would be nice to get some information when things that work before never do it again Sad
At least you can update the manual with a warning.

cheers, michael


It is not necessary to implement ReorderModel, most probably this is a bug!
Thu May 11, 2017 7:47 am View user's profile Send private message
cone



Joined: 29 May 2007
Posts: 322

Post Reply with quote
I guess it is a bug.

If you have the situation as i described on top then the problem is in SortTableModel

Code:

private int[] sortData0() {
   int[] changed = null;

   if (modelEvent == null || modelEvent.getFirstRow() == TableModelEvent.HEADER_ROW) {
      //own event
      boolean shouldSort = tableModel.getRowCount() > 0 && shouldSort();

      if (shouldSort) {
         changed = doSort(null); //sort the rows
      }
      else {
         //get previous indexes
         int[] prevIndexes = new int[sortedIndexes.size()];
         sortedIndexes.fill(prevIndexes);

         changed = prevIndexes;
         reIndex();
      }
   }


It will do a doSort(null); //sort the rows but the sortedIndex is an empty array without fireRowsMapped in TableModel which have to implement now ReorderModel.

cheers, michael
Thu May 11, 2017 8:04 am View user's profile Send private message
cone



Joined: 29 May 2007
Posts: 322

Post Reply with quote
Hi,

did you have the time to have a look at this problem?
Is it a bug?

As a workaround i had to use a SelectionHelper which my colleagues can call before and after they use setRows to preserve the selection Sad

cheers, michael
Wed May 17, 2017 4:31 am View user's profile Send private message
support



Joined: 21 Feb 2006
Posts: 1443

Post Reply with quote
cone wrote:
I guess it is a bug.

If you have the situation as i described on top then the problem is in SortTableModel

Code:

private int[] sortData0() {
   int[] changed = null;

   if (modelEvent == null || modelEvent.getFirstRow() == TableModelEvent.HEADER_ROW) {
      //own event
      boolean shouldSort = tableModel.getRowCount() > 0 && shouldSort();

      if (shouldSort) {
         changed = doSort(null); //sort the rows
      }
      else {
         //get previous indexes
         int[] prevIndexes = new int[sortedIndexes.size()];
         sortedIndexes.fill(prevIndexes);

         changed = prevIndexes;
         reIndex();
      }
   }


It will do a doSort(null); //sort the rows but the sortedIndex is an empty array without fireRowsMapped in TableModel which have to implement now ReorderModel.

cheers, michael


In order for it to go into "doSort(null)", the triggering event should either be null or a 'general' event. If, after adding some rows, you send a rowsInserted event, I don't think there will be a problem.
Wed May 17, 2017 9:07 am View user's profile Send private message
cone



Joined: 29 May 2007
Posts: 322

Post Reply with quote
> rowsInserted event, I don't think there will be a problem.

The problem is that then other listeners get notified and that it was not neccessary before Sad
Wed May 17, 2017 11:50 pm View user's profile Send private message
support



Joined: 21 Feb 2006
Posts: 1443

Post Reply with quote
Ah, I found what the problem is, I will fix it, although I don't understand what you said previously about the selection being cleared.
Fri May 19, 2017 7:09 am View user's profile Send private message
support



Joined: 21 Feb 2006
Posts: 1443

Post Reply with quote
This is now fixed in 4.11.
Wed May 24, 2017 9:09 pm View user's profile Send private message
Display posts from previous:    

Reply to topic    Citra Technologies Forum Index » Report a Bug All times are GMT - 5 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group