Skip to content

Commit debbaf1

Browse files
committed
Handle null return from firebaseApp.get
* Older versions of firebase-messaging such as 19 have this method but will return null.
1 parent 4574702 commit debbaf1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/PushRegistratorFCM.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,17 @@ private String getTokenWithClassFirebaseMessaging() throws ExecutionException, I
125125
// We use firebaseApp.get(FirebaseMessaging.class) instead of FirebaseMessaging.getInstance()
126126
// as the latter uses the default Firebase app. We need to use a custom Firebase app as
127127
// the senderId is provided at runtime.
128-
FirebaseMessaging fcmInstance = firebaseApp.get(FirebaseMessaging.class);
128+
FirebaseMessaging firebaseMessagingInstance = firebaseApp.get(FirebaseMessaging.class);
129+
130+
if (firebaseMessagingInstance == null) {
131+
throw new Error("firebaseMessagingInstance is null");
132+
}
129133

130134
Exception exception;
131135
// FirebaseMessaging.getToken API was introduced in firebase-messaging:21.0.0
132136
try {
133-
Method getTokenMethod = fcmInstance.getClass().getMethod("getToken");
134-
Object tokenTask = getTokenMethod.invoke(fcmInstance);
137+
Method getTokenMethod = firebaseMessagingInstance.getClass().getMethod("getToken");
138+
Object tokenTask = getTokenMethod.invoke(firebaseMessagingInstance);
135139
return Tasks.await((Task<String>)tokenTask);
136140
} catch (NoSuchMethodException e) {
137141
exception = e;

0 commit comments

Comments
 (0)