Skip to content

ref: Narrow Throwable catches to the exceptions they guard (JAVA-552) - #6669

Draft
runningcode wants to merge 6 commits into
9.x.xfrom
no/java-552-narrow-catches
Draft

runningcode wants to merge 6 commits into
9.x.xfrom
no/java-552-narrow-catches

Conversation

@runningcode

@runningcode runningcode commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Replaces catch (Throwable) with the exceptions the guarded code can actually throw, so SDK bugs and fatal errors at these sites are no longer swallowed.

Exceptions:

  • A few sites still catch Exception or RuntimeException, because the guarded code is declared to throw Exception, throws a plain RuntimeException, or is the app's class loader. Each has a comment saying why.
  • Two Build field reads catch NullPointerException, because those fields are only null off-device, such as in unit tests.
  • CanvasStrategy.postSafely drops its catch and checks the result of Handler.post, which returns false instead of throwing when the looper is quitting.
  • The Future.get() catches in DefaultAndroidEventProcessor also restore the interrupt flag.
  • ClientReportRecorder uses a fully qualified java.io.IOException to avoid an import conflict with fix: Rethrow fatal errors at the SDK's boundary catches (JAVA-552) #6665.

💡 Motivation and Context

This is part of the catch (Throwable) audit. It's independent of the other JAVA-552 PRs, so it can merge in any order.

💚 How did you test it?

No new tests. Some existing tests only passed because these catches hid mocks and fakes that don't behave like the real code, so those are fixed.

📝 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.

#skip-changelog

🤖 Generated with Claude Code

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 <[email protected]>
@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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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:34
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 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels 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 <[email protected]>
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 18, 2026
…eny file access

FileOutputStream and File.isFile throw SecurityException when a JVM SecurityManager denies access, so the narrowed catches around the crash marker, the session file and the config file catch it too.

Refs #5513

Refs JAVA-552

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant