From c9e4f689194d4a25023546c71df6a83d4b68f162 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Wed, 8 Apr 2026 19:01:37 -0400 Subject: [PATCH] Return POSITION_NONE in `destroyItem` for null Can't provoke the race, but my theory about https://todo.sr.ht/~singpolyma/soprani.ca/599 is that it's caused by `o == page1.get()` (or `page2.get()`) evaluating to `true` when `page1.get() == null`, causing the item to stick around in the dataset, e.g., during device rotation or some other situation where the view is destroyed, and breaking ViewPager's internal bookkeeping --- .../siacs/conversations/entities/Conversation.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index b86f42cd1b4f071d146547948713dea44f3accd4..f66315df91051abb70fc6ac1b96d16a2f37b33d2 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -2071,8 +2071,16 @@ public class Conversation extends AbstractEntity @Override public int getItemPosition(Object o) { if (mPager.get() != null) { - if (o == page1.get()) return PagerAdapter.POSITION_UNCHANGED; - if (o == page2.get()) return PagerAdapter.POSITION_UNCHANGED; + final var page1Deref = page1.get(); + if (o == page1Deref) { + if (page1Deref == null) return PagerAdapter.POSITION_NONE; + else return PagerAdapter.POSITION_UNCHANGED; + } + final var page2Deref = page2.get(); + if (o == page2Deref) { + if (page2Deref == null) return PagerAdapter.POSITION_NONE; + else return PagerAdapter.POSITION_UNCHANGED; + } } int pos = sessions == null ? -1 : sessions.indexOf(o);