Merge pull request #5596 from esaunders/5637_clear_pages

Cannot call pages.clear() because Lists.partition() returns an unmodi…
This commit is contained in:
Richard Cordovano 2020-01-15 18:40:17 -05:00 committed by GitHub
commit 94e67d8428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -286,8 +286,14 @@ public abstract class BaseChildFactory<T extends Content> extends ChildFactory.D
* If pageSize is set split keys into pages, otherwise create a * If pageSize is set split keys into pages, otherwise create a
* single page containing all keys. * single page containing all keys.
*/ */
if (keys.isEmpty()) { if (keys.isEmpty() && !pages.isEmpty()) {
pages.clear(); /**
* If we previously had keys (i.e. pages is not empty) and now
* we don't have keys, reset pages to an empty list.
* Cannot use a call to List.clear() here because the call to
* Lists.partition() below returns an unmodifiable list.
*/
pages = new ArrayList<>();
} else { } else {
pages = Lists.partition(keys, pageSize > 0 ? pageSize : keys.size()); pages = Lists.partition(keys, pageSize > 0 ? pageSize : keys.size());
} }