Skip to content

Conversation

@shubham1g5
Copy link
Contributor

Product Description

Additional logs to investigate if fcm tokens are getting set to empty.

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@shubham1g5 shubham1g5 added this to the 2.60 milestone Oct 6, 2025
@shubham1g5 shubham1g5 added the skip-integration-tests Skip android tests. label Oct 6, 2025
@shubham1g5 shubham1g5 requested a review from zandre-eng October 6, 2025 10:59
@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

📝 Walkthrough

Walkthrough

The change updates Firebase Cloud Messaging token retrieval handling in FirebaseMessagingUtil.java. It imports org.apache.commons.lang3.StringUtils and modifies the onComplete callback: on success, it retrieves the token as a String and, if non-empty, calls updateFCMToken(token); if empty, it logs an exception indicating an empty token. On failure, it ensures a non-null Throwable by creating a default one when task.getException() is null and logs it. This adds explicit guards against null/empty tokens and standardizes error logging.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant Firebase as FirebaseMessaging
  participant Util as FirebaseMessagingUtil
  participant Logger

  App->>Firebase: requestToken()
  Firebase-->>Util: onComplete(Task<String>)

  alt Success
    Util->>Util: token = task.getResult()
    alt token is non-empty
      Util->>Util: updateFCMToken(token)
    else token is null/empty
      Util->>Logger: logException("Empty FCM token", Throwable)
    end
  else Failure
    Util->>Util: ex = task.getException() or new Throwable("FCM token retrieval failed")
    Util->>Logger: logException("FCM token retrieval error", ex)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • avazirna
  • OrangeAndGreen
  • Jignesh-dimagi

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description only includes the Product Description and Labels and Review sections but omits the required Technical Summary and Feature Flag sections as well as the Safety Assurance section with safety story, test coverage, and QA plan. This does not adhere to the repository’s template, which requires detailed rationale, linked tickets, and safety considerations. Without these elements, the description is incomplete and lacks context for reviewers. It needs more structure and detail to meet the template standards. Please update the PR description to include the missing Technical Summary with ticket links and design rationale, specify any applicable Feature Flag, and provide a Safety Assurance section covering the safety story, automated test coverage, and QA plan.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly identifies the core change of enhancing logging behavior around FCM token nullability. It concisely conveys that the update targets cases of empty or null FCM tokens. The phrasing is precise and directly relates to the modifications in FirebaseMessagingUtil.java. It avoids unnecessary details or noise.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fcmTokenLogging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5e4ba and e04bc80.

📒 Files selected for processing (1)
  • app/src/org/commcare/utils/FirebaseMessagingUtil.java (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/src/org/commcare/utils/FirebaseMessagingUtil.java (1)
app/src/org/commcare/utils/StringUtils.java (1)
  • StringUtils (15-65)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Lint Code Base
🔇 Additional comments (2)
app/src/org/commcare/utils/FirebaseMessagingUtil.java (2)

104-110: LGTM! Empty token guard directly addresses PR objective.

The change adds explicit logging when an empty FCM token is retrieved, which aligns perfectly with the PR's stated objective to diagnose empty FCM token occurrences. The implementation correctly uses StringUtils.isEmpty() to handle both null and empty string cases, preventing invalid tokens from being stored while capturing diagnostic information.


112-114: LGTM! Defensive error handling improvement.

The change ensures that Logger.exception() always receives a non-null Throwable, creating a fallback with a descriptive message when task.getException() returns null. This defensive approach improves the robustness of error logging.

import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.RemoteMessage;

import org.apache.commons.lang3.StringUtils;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

❓ Verification inconclusive

Verify Apache Commons Lang dependency availability.

The code now uses org.apache.commons.lang3.StringUtils.isEmpty() for null/empty token checks. Ensure that Apache Commons Lang is declared as a project dependency (e.g., in build.gradle or similar). Note that a local org.commcare.utils.StringUtils class exists but doesn't provide isEmpty() functionality, so using the external library is appropriate.

Run the following script to verify the dependency is declared:


🏁 Script executed:

#!/bin/bash
# Description: Check if Apache Commons Lang is declared as a dependency

# Check for commons-lang3 in Gradle build files
fd -e gradle -x grep -l "commons-lang3"

# Also check Maven POM files if present
fd -e xml -x grep -l "commons-lang3"

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Refined search for Apache Commons Lang dependency declarations
rg -n "commons-lang3" -g "*.gradle" -g "*.xml"
rg -n "lang3"        -g "*.gradle" -g "*.xml"

Length of output: 0


Add Apache Commons Lang3 dependency
The code uses org.apache.commons.lang3.StringUtils but no commons-lang3 dependency was found in any Gradle or Maven file. Add an appropriate entry (e.g. implementation "org.apache.commons:commons-lang3:3.x.x") to your build configuration.

🤖 Prompt for AI Agents
In app/src/org/commcare/utils/FirebaseMessagingUtil.java around line 22 the code
imports org.apache.commons.lang3.StringUtils but the project has no
commons-lang3 dependency; add the appropriate dependency to the project's build
configuration (for Gradle add implementation
"org.apache.commons:commons-lang3:3.12.0" to the module/app build.gradle
dependencies block or, for Maven, add the corresponding <dependency> entry for
org.apache.commons:commons-lang3 with a 3.x.x version) and then refresh/rebuild
so the import resolves.

Comment on lines +104 to +110
String token = task.getResult();
if (!StringUtils.isEmpty(token)) {
updateFCMToken(token);
} else {
Logger.exception("Fetching FCM registration token failed",
new Throwable("FCM registration token is empty"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you are trying to put the only logs for null fcm token but we should try to put extra code to make sure that fcm token is never null from the mobile at least.

FCM token cannot be null or empty unless task has failed. I think we should have FCM token retrieval mechanism if it's null / empty here or here. This will make sure that fcm token is always present.

Also, there can be issue on server side also which is making the token inactive if failed to send push notification. I have tried to understand that here but seems requires more discussion on it.

Copy link
Contributor Author

@shubham1g5 shubham1g5 Oct 6, 2025

Choose a reason for hiding this comment

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

Think the first step here is to understand what is happening and this PR is aimed to get more insights into question of where it's going wrong (mobile or server).

FCM token cannot be null or empty unless task has failed. I think we should have FCM token retrieval mechanism if it's null / empty here or here. This will make sure that fcm token is always present.

We already do FCM token retreival every time app startup so don't really think adding more code there will help here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah correct. I have feeling that sometimes heartbeat is called before this retrieval take place at app start up but yeah we don't have concrete data for it.

@shubham1g5 shubham1g5 merged commit 980acdc into master Oct 6, 2025
5 of 7 checks passed
@shubham1g5 shubham1g5 deleted the fcmTokenLogging branch October 6, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-integration-tests Skip android tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants