Skip to content

NullPointerException when using cloud messaging #1081

@edonelezovic

Description

@edonelezovic
  • Library version: 9.4.3
  • Firebase Product: cloud messaging

When we are sending messages in bulk to devices using device specific tokens, we randomly get the error below:

java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:595)
	at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:574)
	at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:91)
	at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:67)
	at businessLayer.Messaging.sendPush(Messaging.java:777)
...

We are using the method sendEachAsync:
BatchResponse firebaseResponse = FirebaseMessaging.getInstance(firebaseApp).sendEachAsync(firebaseMessages, pushDryRun).get();

Besides the error showing up randomly when we are sending the messages, it seems that in older version of the library (<= 9.3.0), that the error is:

java.util.concurrent.ExecutionException: com.google.firebase.messaging.FirebaseMessagingException: com.google.firebase.messaging.FirebaseMessaging
	at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:594)
	at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:573)
	at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:91)
	at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:67)
	at businessLayer.Messaging.sendPush(Messaging.java:777)
...

The problem for us is that it seems that this error started showing up randomly last month.
At least some messages seem to be sent, because we have info that users are seeing and clicking on the notifications.
So, it seems that we are correctly calling the procedure.
Any help would be welcomed.

Activity

google-oss-bot

google-oss-bot commented on Feb 28, 2025

@google-oss-bot

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

edonelezovic

edonelezovic commented on Mar 3, 2025

@edonelezovic
Author

We have also started receiving a new error in the same method:

java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: arraycopy: length -24 is negative
	at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:596)
	at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:575)
	at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:91)
	at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:67)
	at businessLayer.Messaging.sendPush(Messaging.java:777)
...
edonelezovic

edonelezovic commented on Apr 2, 2025

@edonelezovic
Author

We made sure the Messages are not null and not empty.

Downgrading didn't prevent an error, but it was a different error, probably isn't handled in the newer version.

Older version:
java.util.concurrent.ExecutionException: com.google.firebase.messaging.FirebaseMessagingException: com.google.firebase.messaging.FirebaseMessaging

Newer version:
java.util.concurrent.ExecutionException: java.lang.NullPointerException

We needed to implement our custom solution using the Firebase Cloud Messaging API, because we didn't know which push messages were being sent and which weren't when the above method returned an exception. We knew that some of the messages were being sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @edonelezovic@google-oss-bot

        Issue actions

          NullPointerException when using cloud messaging · Issue #1081 · firebase/firebase-admin-java