Skip to content

fix: Rethrow fatal errors at the SDK's boundary catches (JAVA-552) - #6665

Draft
runningcode wants to merge 5 commits into
9.x.xfrom
no/java-552-rethrow-if-fatal
Draft

runningcode wants to merge 5 commits into
9.x.xfrom
no/java-552-rethrow-if-fatal

Conversation

@runningcode

@runningcode runningcode commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

The broad catch (Throwable) sites at the SDK's boundaries, where we can't know what the other side throws, also swallowed OutOfMemoryError, StackOverflowError and LinkageError. This PR handles 154 of them:

  • 153 boundaries now call ExceptionUtils.rethrowIfFatal first, with a comment saying why the catch is broad and what is lost when it fails. They guard:
    • Public API entry points in Scopes, LoggerApi, MetricsApi and InternalSentrySdk.
    • User callbacks: the beforeSend* callbacks, beforeBreadcrumb, the samplers, onDiscard, onOversizedEvent, the replay callbacks, the scope callbacks, and the configuration callbacks of Sentry.init and SentryAndroid.init.
    • Data written by earlier launches, other processes or hybrid SDKs: cached envelopes, sessions, outbox items, tombstones, ANR dumps and profiles.
    • Android framework calls that cross into another process, such as PackageManager, ActivityManager and ConnectivityManager.
    • The app's own views, the device's graphics and media stacks (PixelCopy, MediaCodec), and JNI.
    • The JVM integrations: Apollo 3 and 4, Kafka, Logback, Quartz, Spotlight, and the three Spring modules.
  • UncaughtExceptionHandlerIntegration stays broad without rethrowIfFatal, because a rethrow would skip the chained default handler. Only a comment is added.
  • Javadoc on the user-facing callbacks says what is dropped when they throw, that the error is logged at ERROR (which prints only with debug enabled), and that fatal errors are rethrown. This includes Integration.register, and withScope, withIsolationScope and configureScope on IScopes and Sentry.

Some behavior stays as it was:

An OutOfMemoryError while capturing a screenshot or a replay frame now propagates instead of skipping the frame.

This PR doesn't touch any site where a LinkageError is the expected failure. Those are in #6666, so a missing or mismatched optional dependency keeps its old handling.

Mixed sites

These sites need more than one kind of change, so they get their full treatment here:

💡 Motivation and Context

This is part of the catch (Throwable) audit. It replaces the boundary stack #6657 to #6661.

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

The changelog entry here covers the whole set, #6665 to #6670.

💚 How did you test it?

  • The existing unit tests of the changed modules, plus detekt for the Kotlin modules.

📝 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 sentry-docs note on how users find out that their callbacks fail comes with the 9.0.0 migration guide.

🤖 Generated with Claude Code

The broad catches at boundaries, where we can't know what the other side throws, also swallowed OutOfMemoryError, StackOverflowError and LinkageError. They now call ExceptionUtils.rethrowIfFatal first, with a comment saying why the catch is broad and what is lost when it fails. The Javadoc of the user-facing callbacks says what happens when they throw.

Sites where a LinkageError is the expected failure are left alone, so a missing or mismatched optional dependency keeps the old handling.

Refs #5513

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/src/main/java/io/sentry/transport/HttpConnection.java

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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

runningcode and others added 2 commits November 18, 2026 18:33
Refs #5513

Refs JAVA-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runningcode added a commit that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runningcode added a commit that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runningcode added a commit that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Narrowing attachReportToEnvelope to IOException is a narrowing, not a boundary, so it moves to the PR that narrows catches.

Refs #5513

Refs JAVA-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 18, 2026
runningcode added a commit that referenced this pull request Nov 18, 2026
SentryEnvelopeItem.fromClientReport only throws IOException. The name is fully qualified so this PR doesn't touch the import block, where #6665 adds ExceptionUtils right next to it.

Refs #5513

Refs JAVA-552

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: high PR risk score: high labels Nov 18, 2026

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: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant