From 577111cf59ef10d03a26efcbaaea97faf2292f30 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 22 Jul 2020 08:50:20 +0200 Subject: [PATCH] PagedStorage workarounds --- .../java/androidx/paging/PagedStorage.java | 11 ++++++- patches/PagedStorage.patch | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 patches/PagedStorage.patch diff --git a/app/src/main/java/androidx/paging/PagedStorage.java b/app/src/main/java/androidx/paging/PagedStorage.java index c644234c7e..7b2cc1fc78 100644 --- a/app/src/main/java/androidx/paging/PagedStorage.java +++ b/app/src/main/java/androidx/paging/PagedStorage.java @@ -171,6 +171,10 @@ final class PagedStorage extends AbstractList { // can only occur in tiled case, with untouched inner/placeholder pages return null; } + if (pageInternalIndex >= page.size()) { + eu.faircode.email.Log.e("PageStorage pageInternalIndex=" + pageInternalIndex + "/" + page.size()); + return null; + } return page.get(pageInternalIndex); } @@ -542,7 +546,12 @@ final class PagedStorage extends AbstractList { // OK only if existing single page, and it's the last one if (!onlyEndPagePresent && !addingLastPage) { - throw new IllegalArgumentException("page introduces incorrect tiling"); + //throw new IllegalArgumentException("page introduces incorrect tiling"); + eu.faircode.email.Log.e("PagedStorage tiling" + + " size=" + newPageSize + "/" + mPageSize + + " addingLastPage=" + addingLastPage + + " onlyEndPagePresent=" + onlyEndPagePresent); + return; } if (onlyEndPagePresent) { mPageSize = newPageSize; diff --git a/patches/PagedStorage.patch b/patches/PagedStorage.patch new file mode 100644 index 0000000000..d3de421aa0 --- /dev/null +++ b/patches/PagedStorage.patch @@ -0,0 +1,29 @@ +diff --git a/app/src/main/java/androidx/paging/PagedStorage.java b/app/src/main/java/androidx/paging/PagedStorage.java +index c644234c7ed..7b2cc1fc788 100644 +--- a/app/src/main/java/androidx/paging/PagedStorage.java ++++ b/app/src/main/java/androidx/paging/PagedStorage.java +@@ -171,6 +171,10 @@ public T get(int i) { + // can only occur in tiled case, with untouched inner/placeholder pages + return null; + } ++ if (pageInternalIndex >= page.size()) { ++ eu.faircode.email.Log.e("PageStorage pageInternalIndex=" + pageInternalIndex + "/" + page.size()); ++ return null; ++ } + return page.get(pageInternalIndex); + } + +@@ -542,7 +546,12 @@ public void insertPage(int position, @NonNull List page, @Nullable Callback c + + // OK only if existing single page, and it's the last one + if (!onlyEndPagePresent && !addingLastPage) { +- throw new IllegalArgumentException("page introduces incorrect tiling"); ++ //throw new IllegalArgumentException("page introduces incorrect tiling"); ++ eu.faircode.email.Log.e("PagedStorage tiling" + ++ " size=" + newPageSize + "/" + mPageSize + ++ " addingLastPage=" + addingLastPage + ++ " onlyEndPagePresent=" + onlyEndPagePresent); ++ return; + } + if (onlyEndPagePresent) { + mPageSize = newPageSize;