question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IndexOutOfBounds for DataProvider

See original GitHub issue

Created a DataProvider.fromCallbacks object. First page of paging works correctly, second load of data,however causes an indexoutofbounds error: query.getOffset(): 0 query.getLimit(): 50 query.getOffset(): 50 query.getLimit(): 50 java.lang.IndexOutOfBoundsException: Index: 50, Size: 50

java.lang.IndexOutOfBoundsException: Index: 50, Size: 50 at java.util.ArrayList.rangeCheck(ArrayList.java:657) ~[na:1.8.0_212] at java.util.ArrayList.get(ArrayList.java:433) ~[na:1.8.0_212] at com.vaadin.flow.data.provider.DataCommunicator.lambda$getJsonItems$3(DataCommunicator.java:611) ~[flow-data-1.4.6.jar!/:1.4.6]

  • Minimal reproducible example This is about as stripped down as I can make it quickly while keeping this verbose for you…
DataProvider<License,Void> licenseDataProvider = DataProvider.fromCallbacks(
                new CallbackDataProvider.FetchCallback<License, Void>() {
                    @Override
                    Stream<License> fetch(Query<License, Void> query) {
                        println "query.getOffset(): "+query.getOffset()
                        println "query.getLimit(): "+ query.getLimit()
                        Stream<License> licenseStream = licenseRepository.findByZenGroupId(user.getZenGroupId()).subList(query.getOffset(),query.getLimit()).stream()
                        //licensePage = licensePagingRepository.findAllByZenGroupId(user.getZenGroupId(), new PageRequest(query.getOffset(), limit))

                        return licenseStream
                    }
                },new CallbackDataProvider.CountCallback<License, Void>() {
            @Override
            int count(Query<License, Void> query) {
                //println "totalElements:"+licensePagingRepository.findAllByZenGroupId(user.getZenGroupId(), new PageRequest(query.getOffset(), query.getLimit())).getNumber()
                //println "numberOfElements:"+licensePagingRepository.countByZenGroupId(user.getZenGroupId(), new PageRequest(query.getOffset(), query.getLimit()))

                return licenseRepository.countByZenGroupId(user.getZenGroupId())
            }
        })
  • Expected behavior DataProvider lazy loading population to a grid.
  • Actual behavior Crash upon scroll.
  • Versions:
    • Vaadin / Flow version 13.0.10
    • Java version Java: 1.8.212 zulu Spring: Spring boot 2.1.6.RELEASE
    • OS version: Server: Ubuntu
    • Browser version (if applicable) –N/A

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Legiothcommented, Jul 17, 2019

On a completely different note, I’d also like to address this comment:

It is out of scope, to provide you a fully functioning web application to demonstrate your method back to you. This is a unit testing issue on core Vaadin.

In order to determine that the problem was in the example code and not in Vaadin itself, I had to make assumptions about the implementation of the missing classes and how the data provider was used. This was a relatively straightforward case but as an example, the symptoms would have been different if I’d used the data provider with a Select component instead of Grid.

There have also been cases where we have made wrong assumptions without noticing and then ended up only implementing a partial fix or fixing a completely different related issue instead of fixing the issue faced by the reporter.

We are receiving hundreds of reports through open source issue trackers every week. We want to dedicate our time to fixing actual issues or implementing new features rather than filling in blanks in reported issues or making changes that are not helping the reporter. By providing a fully functional example that can be run as-is, you are significantly increasing the chances that you will receive help quickly and efficiently.

In this case, a functionally equivalent self-contained example could have been implemented like this:

@Route
public class Test extends Div {
    public Test() {
        List<String> items = IntStream.range(0, 500).mapToObj(Integer::toString)
                .collect(Collectors.toList());

        DataProvider<String, Void> licenseDataProvider = DataProvider
                .fromCallbacks(query -> {
                    Stream<String> licenseStream = items
                            .subList(query.getOffset(), query.getLimit())
                            .stream();
                    return licenseStream;
                }, query -> items.size());

        Grid<String> grid = new Grid<>();
        grid.setDataProvider(licenseDataProvider);
        grid.addColumn(item -> item);
        add(grid);
    }
}
0reactions
dennisunderwoodcommented, Oct 3, 2019

@jhult I found a solution…we had moved on shortly afterwards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexOutOfBoundsException in DataProvider query using ...
As I wrote in the question I am aware of the meaning of the exception. The DataProvider is used in the scope of...
Read more >
ArrayIndexOutOfBoundsException with @DataProvider in ...
I'm using a data provider for one of tests but am receiving an ArrayIndexOutOfBoundsException when I run the test. ENVIRONMENT TestNG 5.5 --...
Read more >
Grid & Grid Pro IndexOutOfBoundsException - Vaadin
What seems to be the case is that the Spring-data PageRequest.of does not work on the same basis as Vaadin DataProvider.fromCallbacks. The definition...
Read more >
How to fix java.lang.indexoutofboundsexception : invalid array ...
The error is pretty explicit: indexoutofboundsexception : invalid array range: 1 to 1. So somewhere in that code you are using an array...
Read more >
com.businessobjects.rebean.wi Interface DataProviders
The DataProviders interface defines a collection of data providers. ... ArrayIndexOutOfBoundsException - if index is out of range ( index < 0 ||...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found