Repository navigation
ref: Narrow Throwable catches to the exceptions they guard (JAVA-552) - #6669
Draft
runningcode wants to merge 5 commits into
Draft
runningcode wants to merge 5 commits into
runningcode wants to merge 5 commits into
Conversation
Replace catch (Throwable) with the exceptions the guarded code can throw, so SDK bugs and fatal errors at these sites are no longer swallowed. Most are RejectedExecutionException around executor submit and schedule, IOException or SecurityException around file I/O, and the specific parsing exceptions. Several tests only passed because these catches hid mocks that don't behave like the real objects. They now do. Refs #5513 Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 18, 2026
This was referenced Nov 18, 2026
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
Closed
📲 Install BuildsAndroid
|
The fixes to existing tests whose mocks only passed behind broad catches stay. 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>
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
Replace 93
catch (Throwable)with the exceptions the guarded code can throw. SDK bugs and fatal errors at these sites are no longer swallowed:RejectedExecutionExceptionaroundsubmitandschedule, whichISentryExecutorServicedeclares.IOException.SecurityExceptionforFile.delete,renameToandexists, which can throw nothing else.ClientReportRecorder.attachReportToEnvelope:IOException, whichSentryEnvelopeItem.fromClientReportdeclares. The name is fully qualified to keep this PR out of the import block, where fix: Rethrow fatal errors at the SDK's boundary catches (JAVA-552) #6665 addsExceptionUtilson the adjacent line and the two PRs would conflict.Future.get():DefaultAndroidEventProcessor(3):InterruptedException, which now restores the interrupt flag, andExecutionException.SendCachedEnvelopeIntegration: its broad arm is replaced byExecutionExceptionandCancellationException. The executor returns a cancelled future instead of throwing when its queue is full.NumberFormatException,IllegalArgumentException,MalformedURLException,URISyntaxExceptionandPatternSyntaxException.IndexOutOfBoundsException, which an incoming entry without=triggers.NativeEventCollectorcatchesIllegalStateException, which is how the JSON reader reports an unexpected token, andNumberFormatExceptionfor an item length that isn't an int.BaseCaptureStrategy's inline segment persistence catchesIOException, andIndexOutOfBoundsExceptionfor a corrupt segment file line.Exceptionwhere the guarded code is declared to throw it:SentryEnvelopeItem.getData()inNativeEventCollectorandTombstoneIntegration, and the meta lengthCallableinSentryEnvelopeItemHeader.RuntimeExceptionwhere the code throws a plain one:android.os.DebuginAndroidProfiler, andInstallation.id.ManifestModulesLoadercatchesIOException | RuntimeException: the class loader belongs to the app or its container, and can throw anIllegalStateExceptionfor a jar that was already closed. The modules found so far are still cached.ContextUtils.getFamilyandBuildInfoProvider.isEmulatorcatchNullPointerException, sinceBuildfields are only null off-device. Their signatures are unchanged.CanvasStrategy.postSafely:Handler.postdoesn't throw. It returnsfalsewhen the looper is quitting, so the catch is replaced by a check of that result.Mixed sites
These sites need more than one kind of change, so they get their full treatment here:
Future.get()catches inDefaultAndroidEventProcessor: narrowing, plus restoring the interrupt. (SendCachedEnvelopeIntegrationalready keeps the interrupt on9.x.x, so it's only narrowed.)Test changes
Several tests only passed because these catches hid mocks that don't behave like the real objects. They now do:
Unitfromsubmitinstead of aFuture.ContextUtilsTestHelper.createMockContextgave the mockedContextandApplicationno assets. A realContextalways has them.RootCheckerTest's mockedRuntime.execreturnednull.EnvelopeCacheTestfaked a session write failure with aRuntimeException; it now throws anIOException.submitthrowRejectedExecutionExceptioninstead of a plainRuntimeException.💡 Motivation and Context
This is part of the
catch (Throwable)audit. It replaces #6564, and the narrowings in #6657, #6658 and #6659.This PR is independent of its siblings and they can merge in any order:
rethrowIfFatalat boundary sitesLinkageErroris expectedUserInteractionTeststhread-safe list💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
The changelog entry for the whole set is in #6665.
#skip-changelog
🤖 Generated with Claude Code