Android: NoSuchElementException in ScrollIndicators.refit when a scroll view is garbage collected
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Đọc ScrollIndicators.kt, đặc biệt là refit() và releaseAll(), nơi issue báo cáo views.toList() ở cả hai chỗ. Thay các bản sao này bằng cách tiếp cận được đề xuất là dùng ArrayList(views), sau đó chạy các bài kiểm thử Android liên quan hoặc tái hiện trường hợp garbage collection bị buộc được mô tả trong issue. Công việc hoàn tất khi cả hai đường xử lý đều tránh được NoSuchElementException đã báo cáo khi một view được giữ bằng tham chiếu yếu bị thu gom.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
On Android, 1.1.0 crashes with a fatal java.util.NoSuchElementException while a sheet moves. We see it in production on Android 12 and 17 (Samsung devices).
java.util.NoSuchElementException
at java.util.WeakHashMap$HashIterator.nextEntry(WeakHashMap.java:808)
at java.util.WeakHashMap$KeyIterator.next(WeakHashMap.java:839)
at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1346)
at com.swmansion.reactnativebottomsheet.host.ScrollIndicators.refit(ScrollIndicators.kt:52)
at com.swmansion.reactnativebottomsheet.host.Snapping.emitPosition(Snapping.kt:128)
at com.swmansion.reactnativebottomsheet.host.Snapping.snapToIndex$lambda$9$lambda$7(Snapping.kt:230)
at androidx.dynamicanimation.animation.DynamicAnimation.setPropertyValue(DynamicAnimation.java:729)
at androidx.dynamicanimation.animation.DynamicAnimation.doAnimationFrame(DynamicAnimation.java:675)
Cause
ScrollIndicators.views is Collections.newSetFromMap(WeakHashMap()), and refit() / releaseAll() copy it with views.toList(). For a collection of size 1, Kotlin's toList() reads size, then calls iterator().next() without hasNext(). If the garbage collector clears the only view between the two calls, the WeakHashMap iterator has no entry left and throws NoSuchElementException (not a ConcurrentModificationException, since clearing a weak key does not change modCount).
We could reproduce the same stack on an emulator by forcing the key to disappear between size() and iterator().
Suggested fix
Copy the set with ArrayList(views) in refit() and releaseAll(): it goes through AbstractCollection.toArray(), which checks hasNext() before each element. We applied this as a local patch and the forced repro no longer crashes.
- for (view in views.toList()) {
+ for (view in ArrayList(views)) {
main still has views.toList() at both places.
- Ngôn ngữ chính
- Kotlin
- Star
- 536
- Fork
- 24
- Merge trung bình
- 12 giờ 10 phút
- Pull request đã merge (30 ngày)
- 22
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của software-mansion/react-native-bottom-sheet
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 35/100
software-mansion/react-native-bottom-sheet#137 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Feature request: opt-in native keyboard avoidanceCó thể đã có người làm @Asad-Butt đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
software-mansion/react-native-bottom-sheet#134 · 1 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
software-mansion/react-native-bottom-sheet#132 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
software-mansion/react-native-bottom-sheet#74 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
software-mansion/react-native-bottom-sheet#64 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của software-mansion/react-native-bottom-sheet
Issue tương tự
-
Remove Collect againĐang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
thisisartman/Meguri#211 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
follow-up
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:android fleet
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
emm3000/myGame#2175 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày