-
-
Notifications
You must be signed in to change notification settings - Fork 45
Fixes crash on clicking View Job Status #3359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughReplaces 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
TextUtilsimport 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
📒 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_idas a String to directly reading it as an int resolves the crash. The default value of-1appropriately signals a missing or invalid extra, and the guard condition ensuresjobis only initialized with valid data. This eliminates theNumberFormatExceptionrisk and aligns with the fail-fast philosophy for data contract violations.Based on learnings
| String opportunityId = getIntent().getStringExtra(ConnectConstants.OPPORTUNITY_ID); | ||
| if(!TextUtils.isEmpty(opportunityId)){ | ||
| job = ConnectJobUtils.getCompositeJob(this, Integer.parseInt(opportunityId)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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
connectActivityThis is where we add opportunity id to the extras as Integer
Labels and Review