Skip to content
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

[cloud_firestore] Fix possible NullPointerException #31

Closed
wants to merge 14 commits into from
Closed

[cloud_firestore] Fix possible NullPointerException #31

wants to merge 14 commits into from

Conversation

juliocbcotta
Copy link
Contributor

Description

Removed Activity Reference from plugin to avoid possible NullPointerException.
AsyncTasks are not needed to run Transactions, however transactions are not guaranteed run in UI Thread so the Handler is still needed to send data to Dart.

Related Issues

flutter/flutter#38692

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy].
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the [CLA].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Copy link
Contributor

@collinjackson collinjackson left a comment

Choose a reason for hiding this comment

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

It looks like you removed all the AsyncTask calls here and I think that those are necessary so I would be surprised if this works.

I'm seeing integration test failures on Android (note: the Flutterfire CI only runs integration tests on iOS right now but I'm working on fixing that)

Can we keep the AsyncTask part but call result.success() on the original thread?

jackson-macbookpro4:example jackson$ flutter drive test_driver/cloud_firestore.dart 
Found multiple connected devices:
Android SDK built for x86 • emulator-5554                        • android-x86 • Android 9 (API 28) (emulator)
iPhone X                  • 10EBB3FA-C04F-44EA-804B-52DD0C08AC50 • ios         • iOS 12.1 (simulator)
Using device Android SDK built for x86.
Starting application: test_driver/cloud_firestore.dart
Initializing gradle...                                              0.8s
Resolving dependencies...                                           1.6s
"build/app/outputs/apk/app.apk" does not exist.
ERROR: [TAG] Failed to resolve variable '${junit.version}'              
ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}'     
warning: unknown enum constant Scope.LIBRARY_GROUP                      
  reason: class file for android.support.annotation.RestrictTo$Scope not found
warning: unknown enum constant Scope.LIBRARY_GROUP                      
warning: unknown enum constant Scope.LIBRARY_GROUP                      
Note: /Users/jackson/git/plugins_flutterfire/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.                    
Note: /Users/jackson/git/plugins_flutterfire/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.                      
3 warnings                                                              
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        35.8s
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...                         2.4s
I/flutter ( 6004): Observatory listening on http://127.0.0.1:39831/sWZuJW6jnNw=/
[info ] FlutterDriver: Connecting to Flutter application at http://127.0.0.1:59154/sWZuJW6jnNw=/
[trace] FlutterDriver: Isolate found with number: 1242708047141067
[trace] FlutterDriver: Isolate is paused at start.
[trace] FlutterDriver: Attempting to resume isolate
[trace] FlutterDriver: Waiting for service extension
I/flutter ( 6004): 00:00 +0: Firestore getDocumentsWithFirestoreSettings
[info ] FlutterDriver: Connected to Flutter application.
I/flutter ( 6004): 00:00 +1: Firestore getDocumentsFromCollection
I/flutter ( 6004): 00:01 +2: Firestore getDocumentsFromCollectionGroup
I/flutter ( 6004): 00:01 +3: Firestore increment
I/flutter ( 6004): 00:03 +4: Firestore includeMetadataChanges
I/flutter ( 6004): 00:03 +5: Firestore runTransaction
[warning] FlutterDriver: Instance of '_WebSocketImpl' is closed with an unexpected code 1005
[warning] FlutterDriver: Instance of '_WebSocketImpl' is closed with an unexpected code 1005
[warning] FlutterDriver: request_data message is taking a long time to complete...
Stopping application instance.

@@ -419,7 +423,7 @@ public void notImplemented() {
// Wait till transaction is complete.
try {
String timeoutKey = "transactionTimeout";
long timeout = ((Number) arguments.get(timeoutKey)).longValue();
Long timeout = call.argument(timeoutKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

I found this surprising, I would expect that you'd need to call longValue here if an int was passed from Dart. Are you sure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it should work.
If you look here you can see that a dart int can fit a java Long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, I tested. It broke. Moving to Integer solves.

@juliocbcotta
Copy link
Contributor Author

@collinjackson there is no documentation in cloud firestore saying that we need to offload the actions to another thread. With my experience using firebase in android, that is never the case, as any work that need to be in a separated thread is executed with Task api.
If you want I can try to improve the sample so it touches more places in plugin, but I would not recommend bringing the AsyncTasks back.

@juliocbcotta
Copy link
Contributor Author

@collinjackson I partly understood the problem.
When you run a transaction with just one operation it seems to work alright.
When the transaction has multiple operations the AsyncTask makes it work, but it is really odd that need. I included some actions in the example so it will easier to spot.

@juliocbcotta
Copy link
Contributor Author

I am closing this PR as I am not able to keep it updated.

@firebase firebase locked and limited conversation to collaborators Aug 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants