private void ensureDocumentLastPageIsValid(long pagesAmountInFile) {
    Page lastPageInDocument = documentOfPagesModel.getLastPage();
    if (lastPageInDocument.isLastInFile() != (lastPageInDocument.getPageNumber() == pagesAmountInFile - 1)) {
      removeLastPageFromDocument();
      pagesCache.removeIf(page -> lastPageInDocument.getPageNumber() == page.getPageNumber());
    }
  }
private void ensureDocumentLastPageIsValid(long pagesAmountInFile)