Skip to content

fix(replay): Skip the screenshot or frame when its bitmap can't be allocated (JAVA-552) - #6678

Draft
runningcode wants to merge 1 commit into
9.x.xfrom
no/java-552-bitmap-oom
Draft

runningcode wants to merge 1 commit into
9.x.xfrom
no/java-552-bitmap-oom

Conversation

@runningcode

@runningcode runningcode commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

A bitmap of the whole window, recording or SurfaceView is one large allocation. It can fail with an OutOfMemoryError while the rest of the heap is healthy. The SDK now catches the OutOfMemoryError only around its own Bitmap allocations, and skips that screenshot or frame instead of crashing the app:

  • ScreenshotUtils.captureScreenshot: the screenshot is skipped. Hybrid SDKs call this through takeMaskedScreenshot on the UI thread without a catch of their own.
  • CanvasStrategy: the replay frame is skipped, and the next frame tries the allocation again.
  • PixelCopyStrategy: a SurfaceView whose bitmap can't be allocated is left out of the frame. The strategy's own frame bitmap is allocated when the recorder is created, so:
  • WindowRecorder: if creating the recorder runs out of memory, no frames are captured until the next configuration change.

The catches around these allocations are boundaries, so they also get ExceptionUtils.rethrowIfFatal here, with a comment saying why they are broad. That's 8 sites:

  • ScreenshotUtils.captureScreenshot: the PixelCopy request, the draw() posted to the UI thread, and the catch around the whole capture
  • ScreenshotRecorder.capture and WindowRecorder's capture loop
  • PixelCopyStrategy: the PixelCopy request and the SurfaceView capture
  • CanvasStrategy's picture render task

Thread creation isn't covered: an OutOfMemoryError from HandlerThread.start or a timer still crashes, as accepted.

Mixed sites

All 8 sites are mixed: the boundary treatment plus the inner OutOfMemoryError catch around the allocation. They move here from #6665.

💡 Motivation and Context

This is part of the catch (Throwable) audit. A review of #6665 found that adding rethrowIfFatal at these sites turns one failed bitmap allocation into an app crash.

This PR is independent of its siblings and they can merge in any order:

💚 How did you test it?

  • The existing unit tests of sentry-android-core and sentry-android-replay, plus detekt.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

The changelog entry for the whole set is in #6665.

#skip-changelog

🤖 Generated with Claude Code

…located

A bitmap of the whole window, recording or SurfaceView is one large allocation, which can fail with an OutOfMemoryError while the rest of the heap is healthy. The SDK now catches it only around its own Bitmap allocations and skips that screenshot or frame, instead of crashing the app. This matters for hybrid SDKs, which call ScreenshotUtils on the UI thread without a catch of their own.

The screenshot and replay capture catches around these allocations also call ExceptionUtils.rethrowIfFatal now, with a comment saying why they are broad.

Refs #5513

Refs JAVA-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 19, 2026

Copy link
Copy Markdown

JAVA-552

@sentry

sentry Bot commented Nov 19, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.64.0 (1) release

⚙️ sentry-android Build Distribution Settings

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant