Lazy-loading grid data provider throws IndexOutOfBoundsException

I had a grid that uses a ConfigurableFilterDataProvider:

final ConfigurableFilterDataProvider<CompanyListViewDao.Pojo, Void, CompanyListViewDao.Filter> dataProvider =
        DataProvider.<CompanyListViewDao.Pojo, CompanyListViewDao.Filter>fromFilteringCallbacks(companyListViewDao::fetchForGrid, companyListViewDao::countForGrid)
                .withConfigurableFilter();

dataProvider.setFilter(filter);

The countForGrid method is returning 92 and the fetchForGrid method is returning 90 results, but I get an exception:

java.lang.IndexOutOfBoundsException: Index 90 out of bounds for length 90
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
    at java.base/java.util.Objects.checkIndex(Objects.java:385)
    at java.base/java.util.ArrayList.get(ArrayList.java:427)
    at com.vaadin.flow.data.provider.DataCommunicator.lambda$getJsonItems$7(DataCommunicator.java:1453)
    at java.base/java.util.stream.IntPipeline$1$1.accept(IntPipeline.java:180)
    at java.base/java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:104)
    at java.base/java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:712)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at com.vaadin.flow.data.provider.DataCommunicator.getJsonItems(DataCommunicator.java:1455)
    at com.vaadin.flow.data.provider.DataCommunicator.collectChangesToSend(DataCommunicator.java:1393)
    at com.vaadin.flow.data.provider.DataCommunicator.performUpdate(DataCommunicator.java:1273)
...

OH, it’s because my count is greater than the results

Yeah, you want your size and results queries to look pretty much the same in terms of how they’re being filtered, otherwise you’re in for a headache :grinning: