HS-823973: Defer ClientIO init() to prevent JNI crash on Android release mode#321
HS-823973: Defer ClientIO init() to prevent JNI crash on Android release mode#321claudear wants to merge 2 commits into
Conversation
…Android release mode The constructor was eagerly calling init(), which triggers getApplicationDocumentsDirectory() before the Flutter engine/JNI bridge is fully initialized. This causes "No JNI instance is available" errors on Android in release mode. The call() method already has lazy init logic, so removing the eager init() call is safe. Fixes HS-823973 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes an Android release-mode crash by removing the eager
Confidence Score: 4/5Safe for typical API-call flows; the webAuth() OAuth path can crash with an uninitialized cookie jar if a concurrent call() is mid-initialization when the OAuth callback fires. The call() lazy-init path is correctly guarded, but webAuth() uses a bare await init() that returns early if init is already in progress, leaving _cookieJar uninitialized before saveFromResponse is called. lib/src/client_io.dart — specifically the webAuth() method's initialization guard Important Files Changed
|
| endPoint: 'https://cloud.appwrite.io/v1', | ||
| selfSigned: false, | ||
| ); | ||
|
|
||
| // Before any call, client should not be initialized | ||
| expect(client.initialized, isFalse); | ||
|
|
||
| // Trigger initialization by calling init() directly | ||
| await client.init(); | ||
|
|
||
| // After init, client should be initialized | ||
| expect(client.initialized, isTrue); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Test title doesn't match what's actually tested
The test is named 'init() should be called lazily on first API call', but it never exercises the call() code path — it invokes client.init() directly. This means the guard logic in call() (lines 508-513 of client_io.dart) that triggers lazy init is never exercised by any test in this file. If someone accidentally removed or broke that guard, these tests would still pass.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix Confidence: 90/100High confidence because: (1) the stack trace directly points to |
Summary
init()call fromClientIOconstructor that caused "No JNI instance is available" errors on Android in release modeinit()which triggersgetApplicationDocumentsDirectory()before the Flutter engine/JNI bridge is fully readycall()method already has lazy initialization logic (lines 508-513), so the eager call was unnecessaryinit()is not called during constructionTest plan
Client()constructor should no longer throw JNI errorscall())🤖 Generated with Claude Code