Skip to content

fix: Keep handling LinkageError where the SDK expects it (JAVA-552) - #6666

Draft
runningcode wants to merge 4 commits into
9.x.xfrom
no/java-552-linkage-error-sites
Draft

runningcode wants to merge 4 commits into
9.x.xfrom
no/java-552-linkage-error-sites

Conversation

@runningcode

@runningcode runningcode commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

ExceptionUtils.rethrowIfFatal rethrows LinkageError. At the 36 catch (Throwable) sites in this PR, a LinkageError is the expected failure, not a fatal one: a native library that failed to load, a missing optional dependency, or a mismatched Compose or androidx version. Each site keeps handling it, and stops swallowing other fatal errors:

  • Narrowed to the types the guarded code throws, with no broad catch left (16):
    • LoadClass, the Spotlight probe in SentryOptions, and ProfilingServiceLoader
    • NdkIntegration and the SentryNdk native library load
    • AppState, including the AbstractMethodError case from fix: AbstractMethodError when getting Lifecycle #2228
    • The reflection in replay's Windows.kt, Nodes.kt and ComposeViewHierarchyNode, and in SentryComposeHelper
  • Kept broad, because the code calls app views, user integrations or JNI (12). These catch LinkageError first, then call rethrowIfFatal in the catch (Throwable) and say in a comment why it's broad:
    • Integration.register in Sentry.init, and each integration's close() in Scopes.close
    • ViewHierarchyEventProcessor and SentryWindowCallback
    • DebugImagesLoader
    • The OTel SentryContextStorageProvider
    • The Compose traversal in replay's Nodes.kt and ComposeViewHierarchyNode
    • SentrySQLiteDriver.open: androidx.sqlite is compileOnly, so a mismatched version returns the connection uninstrumented, as before.
  • The six event processor loops in SentryClient handle a LinkageError like any other processor failure: an SDK processor is skipped and the event is still sent. Without that, a NoClassDefFoundError in one SDK processor would propagate out of every capture call.

Mixed sites

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

  • WindowManagerSpy in Windows.kt: the reflection is narrowed, and the swap of the root views list moves into swapSafely, a boundary that calls rethrowIfFatal. The swap notifies the root view listeners, so a failing listener no longer leaves the list half swapped.
  • Scopes.close: the catch around the whole shutdown also calls rethrowIfFatal. It encloses the integration close() loop, so a fatal error from an integration only propagates once both catches rethrow it.

💡 Motivation and Context

This is part of the catch (Throwable) audit. Without this PR, adding rethrowIfFatal at these sites would crash apps that work today, for example when the NDK library fails to load, when Sentry.init registers an integration whose optional dependency is missing, or on every touch when the app uses a Compose version that doesn't match. It replaces the LinkageError part of #6562 and #6657.

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

💚 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 changelog entry for the whole set is in #6665.

#skip-changelog

🤖 Generated with Claude Code

ExceptionUtils.rethrowIfFatal rethrows LinkageError. At these sites a LinkageError is the expected failure: a native library that failed to load, a missing optional dependency, or a mismatched Compose or androidx version. Each one is narrowed to the types the guarded code throws, or catches LinkageError before a broad catch that calls rethrowIfFatal.

The event processor loops in SentryClient handle a LinkageError like any other processor failure.

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

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

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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: high PR risk score: high risk: medium PR risk score: medium 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: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant