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

OneSignal.shared.getTags method returns null pointer exception if there are no tags on one signal #15

Closed
isyedaliraza opened this issue Sep 10, 2018 · 1 comment

Comments

@isyedaliraza
Copy link

Description:

Hello, I am using this plugin in one of my projects and the issue is that whenever i call OneSignal.shared.getTags method in my flutter code it gives me null pointer exception. Note that for the first time when the device get registered on one signal there are no tags on onesignal with that device unless you send a tag for the first time. Now in my project every time I have to get old tags from one signal and then delete old tags and then add new tags on one signal. The problem in short that if there are no tags on one signal and you try to call OneSignal.shared.getTags method then you will get a null pointer exception.

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.13.5 17F77, locale en-OM)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3.1)
[✓] Android Studio (version 3.1)
[!] VS Code (version 1.26.1)
[✓] Connected devices (1 available)

! Doctor found issues in 1 category.

One signal plugin version in pubspec.yaml
onesignal: ^1.0.1

Also: I ran the app on android emulator Nexus 4 API 27

Steps to Reproduce Issue:

  1. Setup a new basic flutter project
  2. Register a device on onesignal with OneSignal.shared.init method
  3. try to call OneSignal.shared.getTags method

Anything else:

I think that there is a problem with com.onesignal.flutter.OneSignalSerializer.convertJSONObjectToHashMap method as there is no check on null object If object is null it should not call object.keys().

Or Maybe I am wrong there is some problem with my code. I don't know.

Stack Trace
09-10 15:02:54.970 31812-31910/com.example.app E/AndroidRuntime: FATAL EXCEPTION: OS_GETTAGS_CALLBACK
Process: com.example.app, PID: 31812
java.lang.NullPointerException: Attempt to invoke virtual method
'java.util.Iterator org.json.JSONObject.keys()' on a null object reference at com.onesignal.flutter.OneSignalSerializer.convertJSONObjectToHashMap(OneSignalSerializer.java:202) at com.onesignal.flutter.OSFlutterChangeTagsHandler.tagsAvailable(OneSignalTagsController.java:63) at com.onesignal.OneSignal$14.run(OneSignal.java:1653) at java.lang.Thread.run(Thread.java:764)

@Nightsd01
Copy link
Contributor

Alright! Version 1.0.2 resolves this issue.

@isyedaliraza I want to thank you particularly for posting such a detailed bug report, it really helped to solve the problem!

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

No branches or pull requests

2 participants