Skip to content

fix(android): [Throwable Boundaries 2] Rethrow fatal errors at sentry-android-core boundaries - #6658

Draft
runningcode wants to merge 1 commit into
no/java-552-boundaries-corefrom
no/java-552-boundaries-android-core
Draft

runningcode wants to merge 1 commit into
no/java-552-boundaries-corefrom
no/java-552-boundaries-android-core

Conversation

@runningcode

@runningcode runningcode commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Stack (Throwable Boundaries)


📜 Description

This PR handles the 64 remaining swallowing catch (Throwable) sites in sentry-android-core, including the six sites #6564 left for this pass:

  • 53 boundaries now call ExceptionUtils.rethrowIfFatal first, with a comment saying why the catch is broad and what is lost when it fails. They guard:
    • Binder calls into system services: PackageManager, ActivityManager, ConnectivityManager, ProfilingManager, receiver registration, getExternalFilesDirs.
    • The app's own views and contexts: draw(), getResources(), component callbacks.
    • Data parceled by other processes: battery and broadcast extras, manifest metadata, ApplicationStartInfo.
    • Native or JNI calls: PixelCopy, Bitmap.compress, Choreographer, frame metrics listeners, FileObserver.
    • Files written by crashing processes: tombstones, ANR dumps and profiles.
    • Hybrid SDK entry points in InternalSentrySdk, the ANR profiling thread, and the SentryAndroid.init configuration callback.
  • Narrowed (10):
    • NativeEventCollector: IOException, IllegalStateException (the JSON reader's unexpected token) and NumberFormatException where they apply. Envelope item data uses Exception, which SentryEnvelopeItem.getData() declares.
    • TombstoneIntegration envelope item data: Exception, for the same reason.
    • DefaultAndroidEventProcessor: the three catches around Future.get() now catch InterruptedException (restoring the interrupt flag) and ExecutionException.
    • ContextUtils.getFamily and BuildInfoProvider.isEmulator: NullPointerException, since Build fields are only null off-device. Their signatures are unchanged.
  • Removed (1): the catch around the cached split APK info in ContextUtils, which guarded nothing.
  • ANRWatchDog keeps catching OutOfMemoryError from getProcessesInErrorState before its boundary arm, as Swallow error when reading ActivityManager#getProcessesInErrorState instead of crashing #2114 decided.
  • Javadoc: both SentryAndroid.init overloads that take a configuration now say that init continues with the options set before the configuration threw, that fatal errors are rethrown, and that the failure is logged at ERROR, which prints only with debug enabled.

💡 Motivation and Context

This is the Android part of the rethrowIfFatal boundary pass. It relies on the core part below it in the stack. For example, SentryAndroid.init rethrows a fatal error from the configuration callback, which Sentry.init has to rethrow too.

💚 How did you test it?

  • The unit tests of every changed class.
  • New tests: ANRWatchDog keeps running after an OutOfMemoryError and stops on a StackOverflowError; NativeEventCollector handles a non-numeric item length and a non-object payload; a SentryAndroid configuration handler that throws still leaves the SDK enabled.

📝 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

⚠️ Merge this PR using a merge commit (not squash). Only the bottom of the stack, #6562, is squash-merged into 9.x.x.

#skip-changelog

🤖 Generated with Claude Code

The broad catches left in sentry-android-core guard Binder calls into
system services, the app's own views and contexts, data parceled by other
processes, files written by crashing processes, and the configuration
callback. Call ExceptionUtils.rethrowIfFatal first in each of them, so
OutOfMemoryError, StackOverflowError and LinkageError are no longer
swallowed, and say why the catch is broad and what happens on failure.

getProcessesInErrorState keeps swallowing OutOfMemoryError: unparceling
its reply can fail to allocate without the app being out of memory
(#2114).

Sites whose failures are known are narrowed instead: the native envelope
parsing in NativeEventCollector, the DeviceInfoUtil future in
DefaultAndroidEventProcessor, the Build reads in getFamily and isEmulator,
and the envelope item reads in TombstoneIntegration. The catch around the
cached split APK info guarded nothing and is removed.

SentryAndroid.init now documents what happens when the configuration
handler throws.

Refs JAVA-552

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

linear-code Bot commented Nov 18, 2026

Copy link
Copy Markdown

JAVA-552

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

@sentry

sentry Bot commented Nov 18, 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