Skip to content

fix(jni): ensure that the ScopesAdapter instance is released after use#3411

Merged
buenaflor merged 2 commits into
mainfrom
fix/jni-ref
Dec 18, 2025
Merged

fix(jni): ensure that the ScopesAdapter instance is released after use#3411
buenaflor merged 2 commits into
mainfrom
fix/jni-ref

Conversation

@buenaflor

@buenaflor buenaflor commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

📜 Description

Currently it's not being released and may end up causing a crash due to stale references.

💡 Motivation and Context

Fixes #3410

💚 How did you test it?

Hard to test since it relies on GC.

I have been verifying nothing is crashing by stress testing with thousands of added breadcrumbs in a tight loop.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

…dcrumb and setUser methods

This commit refactors the SentryNativeJava class to improve the retrieval of native options in the addBreadcrumb and setUser methods. The changes ensure that the ScopesAdapter instance is obtained once and used consistently, enhancing code clarity and reducing redundancy. Additionally, null checks are maintained to prevent potential runtime errors.
@buenaflor
buenaflor requested a review from denrase as a code owner December 17, 2025 21:20
Comment thread packages/flutter/lib/src/native/java/sentry_native_java.dart
@github-actions

Copy link
Copy Markdown
Contributor

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 366.66 ms 358.81 ms -7.85 ms
Size 13.93 MiB 15.18 MiB 1.25 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
93b7728 475.28 ms 489.13 ms 13.86 ms
81f83eb 471.40 ms 522.14 ms 50.74 ms
79f6b41 469.66 ms 525.90 ms 56.24 ms
b6c8720 457.41 ms 519.04 ms 61.63 ms
bfabaf2 408.04 ms 444.38 ms 36.34 ms
40c8f93 417.10 ms 482.60 ms 65.50 ms
0fb3800 465.64 ms 536.77 ms 71.13 ms
c26ed0a 465.52 ms 476.38 ms 10.86 ms
cf443d2 464.64 ms 479.04 ms 14.40 ms
a10aff4 488.19 ms 515.02 ms 26.83 ms

App size

Revision Plain With Sentry Diff
93b7728 6.54 MiB 7.69 MiB 1.15 MiB
81f83eb 6.54 MiB 7.69 MiB 1.15 MiB
79f6b41 6.54 MiB 7.69 MiB 1.15 MiB
b6c8720 6.54 MiB 7.69 MiB 1.15 MiB
bfabaf2 13.93 MiB 15.06 MiB 1.13 MiB
40c8f93 13.93 MiB 15.00 MiB 1.06 MiB
0fb3800 6.54 MiB 7.69 MiB 1.15 MiB
c26ed0a 13.93 MiB 14.93 MiB 1.00 MiB
cf443d2 13.93 MiB 15.00 MiB 1.06 MiB
a10aff4 13.93 MiB 15.06 MiB 1.13 MiB

@github-actions

Copy link
Copy Markdown
Contributor

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1253.31 ms 1260.83 ms 7.52 ms
Size 5.53 MiB 5.96 MiB 444.86 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
f761369 1261.69 ms 1277.82 ms 16.12 ms
6b69699 1254.80 ms 1273.31 ms 18.52 ms
819c1e7 1250.59 ms 1249.08 ms -1.51 ms
e0c8591 1259.85 ms 1257.31 ms -2.54 ms
2cb90b9 1272.90 ms 1285.55 ms 12.66 ms
e04b24b 1230.22 ms 1233.90 ms 3.67 ms
8541716 1270.18 ms 1271.80 ms 1.62 ms
9b99523 1256.06 ms 1270.33 ms 14.27 ms
393f8ec 1256.45 ms 1259.60 ms 3.16 ms
e45c0e1 1269.08 ms 1278.83 ms 9.75 ms

App size

Revision Plain With Sentry Diff
f761369 7.86 MiB 9.44 MiB 1.58 MiB
6b69699 7.86 MiB 9.44 MiB 1.58 MiB
819c1e7 5.53 MiB 6.00 MiB 479.96 KiB
e0c8591 5.53 MiB 5.96 MiB 444.86 KiB
2cb90b9 7.86 MiB 9.54 MiB 1.69 MiB
e04b24b 5.53 MiB 6.00 MiB 480.00 KiB
8541716 5.53 MiB 6.00 MiB 479.96 KiB
9b99523 7.86 MiB 9.44 MiB 1.58 MiB
393f8ec 5.53 MiB 6.01 MiB 488.10 KiB
e45c0e1 7.86 MiB 9.44 MiB 1.58 MiB

@denrase denrase left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@buenaflor
buenaflor merged commit 114239b into main Dec 18, 2025
55 checks passed
@buenaflor
buenaflor deleted the fix/jni-ref branch December 18, 2025 10:07
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.

JNI crash (SIGABRT) in addBreadcrumb via ScopesAdapter.getInstance().getOptions() - regression in 9.8.0+

2 participants