Skip to content

Fix android crash when a realm is unreachable - #14

Merged
Imperiopolis merged 1 commit into
juicebox-systems:mainfrom
theapache64:fix/signed-number-crash
Aug 1, 2026
Merged

Fix android crash when a realm is unreachable#14
Imperiopolis merged 1 commit into
juicebox-systems:mainfrom
theapache64:fix/signed-number-crash

Conversation

@theapache64

@theapache64 theapache64 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

context

if one host fails (connectexception), the android http callback builds a fake error response and
hands it back to native. without that completing cleanly, the app dies and never finishes.

previous fix

#13 (#13) (eric) filled in missing fields
on the fake response (id, body, headers) so jni would not panic on null id.
but statuscode = -1 was still there.

why that was not enough

jni reads status as a java short (signed) and converts it to rust u16 with try_into().unwrap().
-1 is valid as a short but not as a non-negative u16, so unwrap still panics in native after the catch.

this change

set statuscode = 0 instead of -1.
0 converts cleanly;
rust treats an invalid/non-success status as a network error for that realm so other realms can still succeed.

test

• [x] block one realm host via custom DNS, enter pin → no crash;
• [x] block all realms → enter pin -> no crash;

if one host fails (connectexception), the android http callback builds a fake error response and
hands it back to native. without that completing cleanly, the app dies and never finishes.

on the fake response (id, body, headers) so jni would not panic on null id.
still set statuscode = -1.

jni reads status as a java short (signed) and converts it to rust u16 with try_into().unwrap().
-1 is valid as a short but not as a non-negative u16, so unwrap still panics in native after the catch.

set statuscode = 0 instead of -1.
0 converts cleanly;
rust treats an invalid/non-success status as a network error for that realm so other realms can still succeed.

• [x] block one realm host via custom DNS, enter pin → no crash;
• [x] block all realms → enter pin -> no crash;
@theapache64

Copy link
Copy Markdown
Contributor Author

@Imperiopolis could you review this? :)

@Imperiopolis
Imperiopolis merged commit f88cd9f into juicebox-systems:main Aug 1, 2026
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