-
Notifications
You must be signed in to change notification settings - Fork 148
HS-823973: Defer ClientIO init() to prevent JNI crash on Android release mode #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
claudear
wants to merge
2
commits into
main
Choose a base branch
from
fix/HS-823973-defer-client-init
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| @TestOn('vm') | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; | ||
| import 'package:appwrite/src/client_io.dart'; | ||
|
|
||
| class FakePathProvider extends PathProviderPlatform { | ||
| late String _tempPath; | ||
|
|
||
| FakePathProvider() { | ||
| _tempPath = Directory.systemTemp.createTempSync('appwrite_test_').path; | ||
| } | ||
|
|
||
| @override | ||
| Future<String?> getApplicationDocumentsPath() async => _tempPath; | ||
| } | ||
|
|
||
| void main() { | ||
| group('ClientIO', () { | ||
| late FakePathProvider fakePathProvider; | ||
|
|
||
| setUp(() { | ||
| fakePathProvider = FakePathProvider(); | ||
| PathProviderPlatform.instance = fakePathProvider; | ||
| }); | ||
|
|
||
| tearDown(() { | ||
| try { | ||
| Directory(fakePathProvider._tempPath).deleteSync(recursive: true); | ||
| } catch (_) {} | ||
| }); | ||
|
|
||
| test('constructor should not eagerly call init()', () { | ||
| // Creating a ClientIO should NOT trigger init() immediately. | ||
| // If init() is called eagerly, it causes "No JNI instance is available" | ||
| // errors on Android in release mode because the platform channels | ||
| // are not yet ready when the constructor runs. | ||
| final client = ClientIO( | ||
| endPoint: 'https://cloud.appwrite.io/v1', | ||
| selfSigned: false, | ||
| ); | ||
|
|
||
| // init() should not have been called yet - initialization should | ||
| // be deferred until the first API call | ||
| expect(client.initProgress, isFalse, | ||
| reason: 'init() should not be called eagerly in the constructor'); | ||
| expect(client.initialized, isFalse, | ||
| reason: 'Client should not be initialized until first API call'); | ||
| }); | ||
|
|
||
| test('init() should be called lazily on first API call', () async { | ||
| final client = ClientIO( | ||
| 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); | ||
| }); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is named
'init() should be called lazily on first API call', but it never exercises thecall()code path — it invokesclient.init()directly. This means the guard logic incall()(lines 508-513 ofclient_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.