Hi,
I am using LQC and the public
List loadItems(int startIndex, int count)
method throws the following exception when there are no items that are returned. In my case there are valid scenario where the List may be of 0 size because there may not be any item to be displayed in table at all.
I think this is a bug in the LQC, can somebody confirm this?
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.vaadin.addons.lazyquerycontainer.LazyQueryView.queryItem(LazyQueryView.java:236)
at org.vaadin.addons.lazyquerycontainer.LazyQueryView.getItem(LazyQueryView.java:209)
at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.getItem(LazyQueryContainer.java:174)
at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.getContainerProperty(LazyQueryContainer.java:184)
at com.vaadin.ui.AbstractSelect.getContainerProperty(AbstractSelect.java:745)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1537)
at com.vaadin.ui.Table.attach(Table.java:2848)
I looked at the LQC code
(LazyQueryView.java:236)
and following seems the bug in the code. Here the for loop assumes that the size of items is always guranteed to be the value of the count which actually does not have to be true, so the for loop should use the items.size() instead of value of the count.
[b]
private void queryItem(final int index) {
…
int count = Math.min(batchSize, getQuery().size() - startIndex);
…
List items = getQuery().loadItems(startIndex, count);
…
for (int i = 0; i < count; i++) {
int itemIndex = startIndex + i;
Item item = items.get(i);
itemCache.put(itemIndex, item);
if (itemCacheAccessLog.contains(itemIndex)) {
itemCacheAccessLog.remove((Object) itemIndex);
}
itemCacheAccessLog.addLast(itemIndex);
}
....
}
[/b]
Thanks,
dheeraj