Azure / Azure/azure-notificationhubs-android

[BUG] onMessageReceived throwing NPE

Open
#286 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
33
Forks
65
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
NPE exception is sometimes thrown when onMessageReceived is invoked. The error was captured a couple of times via Crashlytics so cannot provide the exact state of the device at the time but mostly sure app was in background (98% of captured cases) and got a push notification.

***Exception or Stack Trace***
```
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.microsoft.windowsazure.messaging.notificationhubs.NotificationListener.onPushNotificationReceived(android.content.Context, com.google.firebase.messaging.RemoteMessage)' on a null object reference
at com.microsoft.windowsazure.messaging.notificationhubs.FirebaseReceiver.onMessageReceived(FirebaseReceiver.java:52)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(FirebaseMessagingService.java:235)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(FirebaseMessagingService.java:185)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(FirebaseMessagingService.java:172)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:161)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$com-google-firebase-messaging-EnhancedIntentService(EnhancedIntentService.java:78)
at com.google.firebase.messaging.EnhancedIntentService$$ExternalSyntheticLambda0.run(:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.1.0:2)
at java.lang.Thread.run(Thread.java:920)
```

**To Reproduce**
Steps to reproduce the behavior:

Configure and register with valid credentials + TAG(s)
Receive a push notification (most likely with app on the background / killed)

***Code Snippet***
During main activity onCreate method:

```
NotificationHub.setListener(NotificationDisplayer())

NotificationHub.start(
this.application,
BuildConfig.NOTIFICATION_HUB_NAME,
BuildConfig.NOTIFICATION_HUB_CS
)
```

NotificationDisplayer just set the channels, etc to be able to show the notification.

And once the user is signed in the following is invoked:

`NotificationHub.addTag("[TAG_HERE]")`

**Expected behavior**
No exceptions are thrown and events are handled seamlessly.

**Setup (please complete the following information):**
- OS: Android 10, 11, 12 and 13
- Version of the Library used: 1.1.6

**Information Checklist**
- [X] Bug Description Added
- [X] Repro Steps Added
- [X] Setup information Added

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at FirebaseReceiver.java line 52 and trace how onMessageReceived obtains the NotificationListener. Review the reported startup sequence in the main activity, then reproduce delivery with the app in the background or killed. Done means push notifications no longer throw a NullPointerException and events are handled without exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, azure, firebase, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.