Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE on PageIterator.next() #1503

Closed
goldbal330 opened this issue Aug 11, 2022 · 1 comment
Closed

NPE on PageIterator.next() #1503

goldbal330 opened this issue Aug 11, 2022 · 1 comment

Comments

@goldbal330
Copy link

goldbal330 commented Aug 11, 2022

Describe the bug
NPE sporadically gets thrown by PageIterator (line 74) when PageIterator.hasNext() is invoked.

To Reproduce
Steps to reproduce the behavior:
I was able to reproduce behavior in this simple jUnit Test:

PageIterator<String> pagedIterator = new PagedIterator<>(((List<String[]>)  new ArrayList<
String>[]()).iterator();
Assertions.assertFalse(pagedIterator.hasNext());

It seems like in this corner case currentPage does not get initialized and NPE gets thrown when calling currentPage.length on line 75.

Expected behavior
NPE should not be thrown and hasNext() should return false.

Desktop (please complete the following information):

  • OS: [MacOS]
  • Browser [chrome, safari]
  • Version [1.306]

Additional context
Proposed fix:

  public boolean hasNext() {
        fetch();
        return (currentPage != null && currentPage.length > nextItemIndex);
    }
@bitwiseman
Copy link
Member

PR and test welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants