Skip to content

Fix NPE in PAGImageView.flush() by moving bitmapCache.put() inside the bitmapLock synchronized block.#3429

Merged
shlzxjp merged 1 commit into
mainfrom
bugfix/thunderllei_image_view_npe
May 18, 2026
Merged

Fix NPE in PAGImageView.flush() by moving bitmapCache.put() inside the bitmapLock synchronized block.#3429
shlzxjp merged 1 commit into
mainfrom
bugfix/thunderllei_image_view_npe

Conversation

@leiyue123
Copy link
Copy Markdown
Collaborator

修复 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 作为写入值,避免读取可被其他线程置空的共享字段。

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.56%. Comparing base (2973416) to head (a154efc).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shlzxjp shlzxjp merged commit 05f0806 into main May 18, 2026
9 checks passed
@shlzxjp shlzxjp deleted the bugfix/thunderllei_image_view_npe branch May 18, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants