Skip to content

Commit 114239b

Browse files
authored
fix(jni): ensure that the ScopesAdapter instance is released after use (#3411)
* refactor(sentry_native_java): streamline options retrieval in addBreadcrumb 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. * Update CHANGELOG
1 parent cba2765 commit 114239b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Cold/warm start spans not attaching if TTFD takes more than 3 seconds to report ([#3404](https://github.com/getsentry/sentry-dart/pull/3404))
8+
- Ensure that the JNI `ScopesAdapter` instance is released after use ([#3411](https://github.com/getsentry/sentry-dart/pull/3411))
89

910
## 9.9.0
1011

packages/flutter/lib/src/native/java/sentry_native_java.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,11 @@ class SentryNativeJava extends SentryNativeChannel {
189189
void addBreadcrumb(Breadcrumb breadcrumb) =>
190190
tryCatchSync('addBreadcrumb', () {
191191
using((arena) {
192-
final nativeOptions = native.ScopesAdapter.getInstance()?.getOptions()
192+
final scopesAdapter = native.ScopesAdapter.getInstance()
193193
?..releasedBy(arena);
194-
if (nativeOptions == null) return;
194+
if (scopesAdapter == null) return;
195+
final nativeOptions = scopesAdapter.getOptions()..releasedBy(arena);
196+
195197
final jMap = dartToJMap(breadcrumb.toJson());
196198
final nativeBreadcrumb =
197199
native.Breadcrumb.fromMap(jMap, nativeOptions)
@@ -214,10 +216,10 @@ class SentryNativeJava extends SentryNativeChannel {
214216
if (user == null) {
215217
native.Sentry.setUser(null);
216218
} else {
217-
final nativeOptions = native.ScopesAdapter.getInstance()
218-
?.getOptions()
219+
final scopesAdapter = native.ScopesAdapter.getInstance()
219220
?..releasedBy(arena);
220-
if (nativeOptions == null) return;
221+
if (scopesAdapter == null) return;
222+
final nativeOptions = scopesAdapter.getOptions()..releasedBy(arena);
221223

222224
final jMap = dartToJMap(user.toJson());
223225
final nativeUser = native.User.fromMap(jMap, nativeOptions)

0 commit comments

Comments
 (0)