Fix NPE in PAGImageView.flush() by moving bitmapCache.put() inside the bitmapLock synchronized block.#3429
Merged
Merged
Conversation
…e bitmapLock synchronized block.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3429 +/- ##
==========================================
+ Coverage 81.55% 81.56% +0.01%
==========================================
Files 558 558
Lines 51407 51407
Branches 13875 13987 +112
==========================================
+ Hits 41924 41931 +7
+ Misses 6603 6600 -3
+ Partials 2880 2876 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
shlzxjp
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 PAGImageView 在开启 cacheAllFramesInMemory 时的偶发 NPE。
问题:flush() 中 bitmapCache.put(frame, renderBitmap) 在 synchronized(bitmapLock) 块外执行,而 renderBitmap 是 volatile 字段,可能被 releaseBitmap() 并发置为 null,导致 ConcurrentHashMap.put 因 value 为 null 抛出 NullPointerException。原有的 renderBitmap != null 预检查仍存在 TOCTOU 窗口,无法防护。
修复:将 bitmapCache.put 调用移入 synchronized(bitmapLock) 块内,与 releaseBitmap() 互斥;同时改用局部变量 flushBitmap 作为写入值,避免读取可被其他线程置空的共享字段。