Repository navigation
fix: Rethrow fatal errors at the SDK's boundary catches (JAVA-552) - #6665
Draft
runningcode wants to merge 5 commits into
Draft
runningcode wants to merge 5 commits into
runningcode wants to merge 5 commits into
Conversation
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>
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:
|
This was referenced Nov 18, 2026
This was referenced Nov 18, 2026
Closed
📲 Install BuildsAndroid
|
Refs #5513 Refs JAVA-552 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>
This branch has not been deployed
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.
📜 Description
The broad
catch (Throwable)sites at the SDK's boundaries, where we can't know what the other side throws, also swallowedOutOfMemoryError,StackOverflowErrorandLinkageError. This PR handles 154 of them:ExceptionUtils.rethrowIfFatalfirst, with a comment saying why the catch is broad and what is lost when it fails. They guard:Scopes,LoggerApi,MetricsApiandInternalSentrySdk.beforeSend*callbacks,beforeBreadcrumb, the samplers,onDiscard,onOversizedEvent, the replay callbacks, the scope callbacks, and the configuration callbacks ofSentry.initandSentryAndroid.init.PackageManager,ActivityManagerandConnectivityManager.PixelCopy,MediaCodec), and JNI.UncaughtExceptionHandlerIntegrationstays broad withoutrethrowIfFatal, because a rethrow would skip the chained default handler. Only a comment is added.debugenabled), and that fatal errors are rethrown. This includesIntegration.register, andwithScope,withIsolationScopeandconfigureScopeonIScopesandSentry.Some behavior stays as it was:
withScope,withIsolationScopeandconfigureScopestill swallow the callback's non-fatal exceptions.ANRWatchDogstill catches theOutOfMemoryErrorfromgetProcessesInErrorState, as Swallow error when reading ActivityManager#getProcessesInErrorState instead of crashing #2114 decided.An
OutOfMemoryErrorwhile capturing a screenshot or a replay frame now propagates instead of skipping the frame.This PR doesn't touch any site where a
LinkageErroris 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:
AnrV2Integration, reading the ANR trace: ref: Narrow Throwable catches to the exceptions they guard (JAVA-552) #6564 had it as a narrowing, butgetTraceInputStream()is a Binder call, so it's a boundary.ANRWatchDog.getProcessesInErrorState: theOutOfMemoryErrorarm and the boundary.💡 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:
LinkageErroris expectedUserInteractionTeststhread-safe listThe changelog entry here covers the whole set, #6665 to #6670.
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
🤖 Generated with Claude Code