Skip to content

Conversation

@buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Nov 27, 2025

Fixes conversion of non-supported types in Dart conversion to JNI types.

What we want: if we try to convert an unsupported type we just fallback to its .toString() representation

💚 How did you test it?

Integration test. manual test

📝 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

Comment on lines +391 to 423
@visibleForTesting
JObject dartToJObject(Object? value) => switch (value) {
String s => s.toJString(),
bool b => b.toJBoolean(),
int i => i.toJLong(),
double d => d.toJDouble(),
List<dynamic> l => _dartToJList(l),
Map<String, dynamic> m => _dartToJMap(m),
_ => null
List<dynamic> l => dartToJList(l),
Map<String, dynamic> m => dartToJMap(m),
_ => value.toString().toJString()
};

JList<JObject?> _dartToJList(List<dynamic> values) {
final jList = JList.array(JObject.nullableType);
for (final v in values) {
final j = _dartToJObject(v);
@visibleForTesting
JList<JObject> dartToJList(List<dynamic> values) {
final jList = JList.array(JObject.type);
for (final v in values.nonNulls) {
final j = dartToJObject(v);
jList.add(j);
j?.release();
j.release();
}
return jList;
}

JMap<JString, JObject?> _dartToJMap(Map<String, dynamic> json) {
final jMap = JMap.hash(JString.type, JObject.nullableType);
for (final entry in json.entries) {
@visibleForTesting
JMap<JString, JObject> dartToJMap(Map<String, dynamic> json) {
final jMap = JMap.hash(JString.type, JObject.type);
for (final entry in json.entries.where((e) => e.value != null)) {
final jk = entry.key.toJString();
final jv = _dartToJObject(entry.value);
final jv = dartToJObject(entry.value);
jMap[jk] = jv;
jk.release();
jv?.release();
jv.release();
}
return jMap;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

java drops null values so we can just directly filter null values out

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (e0c8591) to head (9135ca4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3372      +/-   ##
==========================================
+ Coverage   88.67%   91.43%   +2.76%     
==========================================
  Files         291       95     -196     
  Lines        9957     3198    -6759     
==========================================
- Hits         8829     2924    -5905     
+ Misses       1128      274     -854     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1257.96 ms 1252.71 ms -5.24 ms
Size 5.53 MiB 5.96 MiB 444.85 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
af96ef2 1260.79 ms 1259.61 ms -1.17 ms
1f639ee 1252.43 ms 1257.82 ms 5.38 ms
7cfee3b 1260.90 ms 1273.14 ms 12.24 ms
73a3c38 1263.37 ms 1277.90 ms 14.53 ms
3615e19 1225.02 ms 1234.57 ms 9.55 ms
6e7d494 1261.37 ms 1265.35 ms 3.99 ms
6ad8fc4 1263.70 ms 1266.06 ms 2.36 ms
c8596a6 1234.11 ms 1241.19 ms 7.08 ms
c0dde50 1268.90 ms 1275.61 ms 6.71 ms
e5b87f8 1257.94 ms 1261.90 ms 3.96 ms

App size

Revision Plain With Sentry Diff
af96ef2 5.53 MiB 6.02 MiB 501.31 KiB
1f639ee 5.53 MiB 6.00 MiB 479.95 KiB
7cfee3b 20.70 MiB 22.46 MiB 1.75 MiB
73a3c38 7.86 MiB 9.44 MiB 1.58 MiB
3615e19 7.86 MiB 9.44 MiB 1.58 MiB
6e7d494 5.53 MiB 6.01 MiB 488.14 KiB
6ad8fc4 5.53 MiB 6.01 MiB 487.65 KiB
c8596a6 7.86 MiB 9.44 MiB 1.58 MiB
c0dde50 5.53 MiB 6.01 MiB 488.14 KiB
e5b87f8 5.53 MiB 6.02 MiB 502.11 KiB

Previous results on branch: fix/ffi-jni-serialization

Startup times

Revision Plain With Sentry Diff
9135ca4 1257.13 ms 1259.59 ms 2.46 ms
7dc837d 1249.71 ms 1247.00 ms -2.71 ms
735ff6e 1256.56 ms 1256.39 ms -0.17 ms
3510c6f 1241.68 ms 1252.94 ms 11.26 ms
9e0ccbe 1261.90 ms 1256.69 ms -5.20 ms
07d2248 1270.16 ms 1271.49 ms 1.33 ms
5f689b3 1260.00 ms 1270.98 ms 10.98 ms
927702d 1263.04 ms 1267.00 ms 3.96 ms
2d05329 1242.23 ms 1240.61 ms -1.62 ms
0ea034a 1248.35 ms 1251.65 ms 3.30 ms

App size

Revision Plain With Sentry Diff
9135ca4 5.53 MiB 5.96 MiB 444.85 KiB
7dc837d 5.53 MiB 6.02 MiB 501.38 KiB
735ff6e 5.53 MiB 5.96 MiB 444.85 KiB
3510c6f 5.53 MiB 5.96 MiB 444.86 KiB
9e0ccbe 5.53 MiB 6.02 MiB 501.39 KiB
07d2248 5.53 MiB 6.02 MiB 501.40 KiB
5f689b3 5.53 MiB 6.02 MiB 501.40 KiB
927702d 5.53 MiB 5.96 MiB 444.85 KiB
2d05329 5.53 MiB 6.02 MiB 501.39 KiB
0ea034a 5.53 MiB 6.02 MiB 501.39 KiB

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 405.69 ms 396.57 ms -9.11 ms
Size 13.93 MiB 15.18 MiB 1.25 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
a10aff4 488.19 ms 515.02 ms 26.83 ms
396cb30 405.70 ms 427.56 ms 21.86 ms
7cfee3b 498.78 ms 516.98 ms 18.20 ms
c8596a6 474.00 ms 492.96 ms 18.96 ms
944b773 470.54 ms 480.18 ms 9.64 ms
29e8ebe 389.91 ms 395.76 ms 5.84 ms
1f639ee 429.98 ms 476.60 ms 46.62 ms
e5b87f8 371.22 ms 377.22 ms 6.00 ms
d3fb366 391.49 ms 385.85 ms -5.64 ms
3615e19 468.38 ms 504.71 ms 36.33 ms

App size

Revision Plain With Sentry Diff
a10aff4 13.93 MiB 15.06 MiB 1.13 MiB
396cb30 13.93 MiB 15.06 MiB 1.13 MiB
7cfee3b 6.54 MiB 7.70 MiB 1.17 MiB
c8596a6 6.54 MiB 7.53 MiB 1015.27 KiB
944b773 13.93 MiB 15.00 MiB 1.06 MiB
29e8ebe 13.93 MiB 15.06 MiB 1.13 MiB
1f639ee 13.93 MiB 15.00 MiB 1.06 MiB
e5b87f8 13.93 MiB 15.18 MiB 1.25 MiB
d3fb366 13.93 MiB 15.06 MiB 1.13 MiB
3615e19 6.54 MiB 7.70 MiB 1.16 MiB

Previous results on branch: fix/ffi-jni-serialization

Startup times

Revision Plain With Sentry Diff
5f689b3 382.34 ms 414.06 ms 31.72 ms
0ea034a 376.96 ms 389.88 ms 12.92 ms
9135ca4 387.31 ms 382.31 ms -5.00 ms
927702d 366.96 ms 373.96 ms 7.00 ms
7dc837d 442.74 ms 487.54 ms 44.80 ms
735ff6e 372.98 ms 372.71 ms -0.26 ms
07d2248 365.62 ms 365.57 ms -0.06 ms
9e0ccbe 369.40 ms 368.20 ms -1.19 ms
2d05329 410.74 ms 425.51 ms 14.77 ms

App size

Revision Plain With Sentry Diff
5f689b3 13.93 MiB 15.18 MiB 1.25 MiB
0ea034a 13.93 MiB 15.18 MiB 1.25 MiB
9135ca4 13.93 MiB 15.18 MiB 1.25 MiB
927702d 13.93 MiB 15.18 MiB 1.25 MiB
7dc837d 13.93 MiB 15.18 MiB 1.25 MiB
735ff6e 13.93 MiB 15.18 MiB 1.25 MiB
07d2248 13.93 MiB 15.18 MiB 1.25 MiB
9e0ccbe 13.93 MiB 15.18 MiB 1.25 MiB
2d05329 13.93 MiB 15.18 MiB 1.25 MiB

@buenaflor buenaflor changed the title fix(jni/ffi): dart to native type conversion [draft] fix(jni): dart to native type conversion Dec 9, 2025
@buenaflor buenaflor marked this pull request as draft December 9, 2025 13:38
This commit introduces a new test file for verifying the conversion of Dart objects to JNI types, including primitives, lists, and maps. The tests ensure that null values are dropped appropriately and that nested structures are handled correctly. The tests are designed to run on the Android platform only.
@buenaflor buenaflor marked this pull request as ready for review December 9, 2025 22:20
@buenaflor buenaflor changed the title [draft] fix(jni): dart to native type conversion fix(jni): dart to native type conversion Dec 9, 2025
This commit updates the JNI utility tests by renaming assertion functions for better readability and consistency. The changes include replacing direct assertions with dedicated helper functions that check for equality, ensuring null checks are performed, and enhancing the overall structure of the test cases. This refactor aims to improve maintainability and clarity in the test suite.
Copy link
Collaborator

@denrase denrase left a comment

Choose a reason for hiding this comment

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

Just the one comment that we need to check.

This commit updates the JNI utility tests by restructuring the test cases for better clarity and maintainability. Key changes include the introduction of local variables for input data, improved assertion handling with arena management, and the renaming of helper functions for consistency. These modifications aim to streamline the testing process and ensure accurate validation of Dart to JNI object conversions.
…readability

This commit introduces line breaks in the JNI utility test file to enhance the overall readability of the code. The changes aim to improve the visual structure of the test cases, making it easier to follow the logic and organization of the tests.
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.

3 participants