Skip to content

Conversation

@shubham1g5
Copy link
Contributor

@shubham1g5 shubham1g5 commented Oct 7, 2025

Product Description

https://dimagi.atlassian.net/browse/QA-8141

crash

Technical Summary

We were using incorrect data type for opportunity id which was resulting in the job to be set as null for connectActivity

This is where we add opportunity id to the extras as Integer

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

📝 Walkthrough

Walkthrough

Replaces parsing of opportunity_id from a String intent extra with direct retrieval as an int (default -1). Removes TextUtils checks and NumberFormatException risk. The composite job is now created only when the retrieved int extra is not -1; otherwise, no job is initialized. No public API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as User
  participant OS as Android OS
  participant Activity as ConnectActivity
  participant Intent as Intent
  participant Jobs as CompositeJobFactory

  User->>OS: Launch ConnectActivity
  OS->>Activity: onCreate(intent)
  Activity->>Intent: getIntExtra("opportunity_id", -1)
  Intent-->>Activity: opportunityId (int)
  alt opportunityId != -1
    Activity->>Jobs: createCompositeJob(opportunityId)
    Jobs-->>Activity: job
    Note right of Activity: Job initialized
  else opportunityId == -1
    Note right of Activity: Skip job creation
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • OrangeAndGreen
  • Jignesh-dimagi

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description provides a link to the related Jira ticket and a brief technical summary but omits several required template sections such as Safety Assurance (safety story, automated test coverage, QA plan) and does not explicitly address feature flags or release notes as outlined by the repository template. Please update the description to include the Safety Assurance section with a safety story, automated test coverage details, and a QA plan, and add or remove the Feature Flag and Release Note sections as appropriate per the repository template.
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 succinctly describes the main change by indicating it resolves a crash when clicking “View Job Status,” which aligns precisely with the context of the code changes in ConnectActivity without extraneous detail.
✨ 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 fixIntentType

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: 0

🧹 Nitpick comments (1)
app/src/org/commcare/activities/connect/ConnectActivity.java (1)

13-13: Remove unused import.

The TextUtils import is no longer used after switching from String to int retrieval. Consider removing this import to keep the code clean.

Apply this diff to remove the unused import:

-import android.text.TextUtils;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 938597b and 2d109d0.

📒 Files selected for processing (1)
  • app/src/org/commcare/activities/connect/ConnectActivity.java (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-29T14:10:55.131Z
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#3248
File: app/src/org/commcare/fragments/connect/ConnectUnlockFragment.java:0-0
Timestamp: 2025-07-29T14:10:55.131Z
Learning: In ConnectUnlockFragment.java, opportunityId values are expected to always contain valid integer strings. Integer.parseInt() should be allowed to throw NumberFormatException if invalid data is encountered, following the fail-fast philosophy used throughout the Connect feature for data contract violations.

Applied to files:

  • app/src/org/commcare/activities/connect/ConnectActivity.java
🧬 Code graph analysis (1)
app/src/org/commcare/activities/connect/ConnectActivity.java (2)
app/src/org/commcare/connect/ConnectConstants.java (1)
  • ConnectConstants (8-49)
app/src/org/commcare/connect/database/ConnectJobUtils.java (1)
  • ConnectJobUtils (25-383)
🔇 Additional comments (1)
app/src/org/commcare/activities/connect/ConnectActivity.java (1)

84-87: Fix correctly addresses the root cause.

The change from retrieving opportunity_id as a String to directly reading it as an int resolves the crash. The default value of -1 appropriately signals a missing or invalid extra, and the guard condition ensures job is only initialized with valid data. This eliminates the NumberFormatException risk and aligns with the fail-fast philosophy for data contract violations.

Based on learnings

Comment on lines -84 to -86
String opportunityId = getIntent().getStringExtra(ConnectConstants.OPPORTUNITY_ID);
if(!TextUtils.isEmpty(opportunityId)){
job = ConnectJobUtils.getCompositeJob(this, Integer.parseInt(opportunityId));
Copy link
Contributor

Choose a reason for hiding this comment

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

@shubham1g5 Just trying to understand here, what is the reason that it was failing? code looks ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getIntent().getStringExtra returns null if the extra is not a String data type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

offline with Jignesh here and seems like we are sending it as String at a bunch of places in Push notifications code, so going to go with dual parsing here as both String and Int

…s we are using both data types in different places in code
@shubham1g5 shubham1g5 merged commit 8b12f09 into commcare_2.60 Oct 8, 2025
1 of 2 checks passed
@shubham1g5 shubham1g5 deleted the fixIntentType branch October 8, 2025 09:08
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