Skip to content

fix(ADFA-3083): Use getOrDefault to prevent exceptions when fetching absent datasets#1044

Merged
dara-abijo-adfa merged 3 commits intostagefrom
ADFA-3083-out-of-bounds-exception
Mar 10, 2026
Merged

fix(ADFA-3083): Use getOrDefault to prevent exceptions when fetching absent datasets#1044
dara-abijo-adfa merged 3 commits intostagefrom
ADFA-3083-out-of-bounds-exception

Conversation

@dara-abijo-adfa
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f85750df-f882-4197-bd72-b8e6727bee91

📥 Commits

Reviewing files that changed from the base of the PR and between 47605da and c6197a2.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt

📝 Walkthrough
  • Fix: Prevent IndexOutOfBoundsException in memory usage chart by using pidToDatasetIdxMap.getOrDefault(proc.pid, -1) when fetching datasets instead of direct map access.
  • Optimization: Introduced a local dataChanged flag inside MemoryUsageWatcher.MemoryUsageListener to track whether any dataset entries were updated during a memory update cycle.
  • Behavior: Only triggers chart refresh (data.notifyDataChanged(), notifyDataSetChanged(), invalidate()) when dataChanged is true — avoids unnecessary UI refreshes.
  • Implementation details: Uses a -1 sentinel for missing mappings and null-safe cast to LineDataSet? before updating entries; no public API or method-signature changes.
  • Risk / Best-practice notes:
    • Low risk: change is localized to UI memory-chart logic and has no public API impact.
    • Defensive pattern is appropriate, but relying on a -1 sentinel assumes data.getDataSetByIndex(-1) returns null or is handled safely; if that method ever throws on negative indices, regressions could occur. Consider validating index >= 0 before calling getDataSetByIndex to be explicit.
    • Minor runtime overhead from the extra boolean is negligible.

Walkthrough

The MemoryUsageWatcher.MemoryUsageListener now uses getOrDefault() when mapping pids to dataset indices and introduces a local dataChanged flag to track per-update modifications; chart data refresh (notifyDataChanged/notifyDataSetChanged/invalidate) runs only if any dataset changed.

Changes

Cohort / File(s) Summary
Memory Usage Monitoring Safety
app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt
Added a local dataChanged flag to aggregate dataset updates; replaced pidToDatasetIdxMap[proc.pid] with pidToDatasetIdxMap.getOrDefault(proc.pid, -1) to avoid missing-key issues; conditional chart refresh invoked only when dataChanged is true.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I nibble code where numbers play,
A tiny flag hops out to say,
"If data moved, then redraw bright"—
Else sleep and keep the view just right. 🥕📊

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No description was provided by the author. The pull request lacks any explanation of changes, rationale, or context. Add a description explaining the problem being fixed, the solution implemented, and any relevant testing or impact information.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing dataset lookup with getOrDefault to prevent exceptions when accessing missing mappings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ADFA-3083-out-of-bounds-exception

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.

@dara-abijo-adfa dara-abijo-adfa merged commit e420cc3 into stage Mar 10, 2026
2 checks passed
@dara-abijo-adfa dara-abijo-adfa deleted the ADFA-3083-out-of-bounds-exception branch March 10, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants