diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index fc95312ea..cea06b942 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -1089,15 +1089,25 @@ public class SearchFragment extends BaseListFragment result) { showListFooter(false); infoListAdapter.addInfoItemList(result.getItems()); - nextPage = result.getNextPage(); - if (!result.getErrors().isEmpty() && nextPage != null) { - showSnackBarError(new ErrorInfo(result.getErrors(), UserAction.SEARCHED, - "\"" + searchString + "\" → pageUrl: " + nextPage.getUrl() + ", " - + "pageIds: " + nextPage.getIds() + ", " - + "pageCookies: " + nextPage.getCookies(), - serviceId)); + if (!result.getErrors().isEmpty()) { + // nextPage should be non-null at this point, because it refers to the page + // whose results are handled here, but let's check it anyway + if (nextPage == null) { + showSnackBarError(new ErrorInfo(result.getErrors(), UserAction.SEARCHED, + "\"" + searchString + "\" → nextPage == null", serviceId)); + } else { + showSnackBarError(new ErrorInfo(result.getErrors(), UserAction.SEARCHED, + "\"" + searchString + "\" → pageUrl: " + nextPage.getUrl() + ", " + + "pageIds: " + nextPage.getIds() + ", " + + "pageCookies: " + nextPage.getCookies(), + serviceId)); + } } + + // keep the reassignment of nextPage after the error handling to ensure that nextPage + // still holds the correct value during the error handling + nextPage = result.getNextPage(); super.handleNextItems(result); }