Skip to content

ADFA-3030 | Prevent tab access crash when content is null#1023

Merged
jatezzz merged 5 commits intostagefrom
fix/ADFA-3030-null-content-tab-access
Mar 3, 2026
Merged

ADFA-3030 | Prevent tab access crash when content is null#1023
jatezzz merged 5 commits intostagefrom
fix/ADFA-3030-null-content-tab-access

Conversation

@jatezzz
Copy link
Collaborator

@jatezzz jatezzz commented Feb 26, 2026

Description

This PR adds minimal null-safety guards around tab/content access paths that can run after the activity is destroyed (e.g., with “Don’t keep activities” enabled).
It prevents NullPointerException/state issues by early-returning when contentOrNull is unavailable, while keeping existing behavior unchanged in normal flows.

Details

Before fix

Before.fix.mov
Before fix

After fix

After.fix.mov

Ticket

ADFA-3030

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd5c9b and d1c00ed.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt

📝 Walkthrough

Release Notes - ADFA-3030: Prevent Tab Access Crash When Content Is Null

  • Changes

    • Added null-safety guards in EditorHandlerActivity to avoid accessing content/binding after Activity destruction.
    • Methods updated:
      • getTabPositionForFileIndex() — uses safeContent and totalTabs; returns -1 if content is null.
      • getNextFileTabPosition() — uses safeContent and totalTabs; returns -1/0 when content is null or no eligible tab exists.
      • isPluginTab() — returns false when content is null; validates position against totalTabs before checking plugin map.
      • openFileAndGetIndex() / openFile handling — use safeContent and totalTabs for tab creation/insertion.
      • updateTabVisibility() — early-returns when content is null and applies visibility updates to safeContent.
    • Replaced direct content/binding references with local safeContent references across affected code paths.
    • Diff summary: approximately +23 / -11 lines.
  • Problem Resolved

    • Prevents IllegalStateException: "Activity destroyed; binding not accessible" that occurred when coroutine/async paths accessed view binding after the activity was destroyed (e.g., with "Don't keep activities" enabled).
  • Risk Assessment / Best-Practice Notes

    • ⚠️ This is a defensive, minimal fix: early-returns prevent crashes but do not stop async work from running after activity destruction.
    • Could mask improper coroutine/lifecycle handling: long-running coroutines continuing after destroy remain possible.
    • Recommend addressing root cause by scoping/cancelling coroutines with lifecycle-aware scopes (e.g., lifecycleScope, viewModelScope) or explicitly cancelling jobs on onDestroy.
  • Testing Recommendations

    • Reproduce scenario with "Don't keep activities" enabled and verify no crash.
    • Verify normal tab/file operations and tab visibility remain unchanged when content is present.
    • Test flows that may now early-return to ensure there are no UI/state inconsistencies or missed cleanup.
  • Backwards Compatibility

    • No public API changes; behavior is unchanged in normal flows when content is available.

Walkthrough

Adds null-safety guards to tab- and content-related operations in EditorHandlerActivity: methods now use a local safeContent reference, compute totalTabs, validate indices, and return early when content is null to prevent potential NPEs.

Changes

Cohort / File(s) Summary
Null-safety updates
app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt
Introduced safeContent and totalTabs local references; added null checks and bounds validation in getTabPositionForFileIndex, getNextFileTabPosition, isPluginTab, openFileAndGetIndex, openFile, and updateTabVisibility; replaced direct content usages with safeContent and return early when null.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • dara-abijo-adfa
  • Daniel-ADFA
  • itsaky-adfa

Poem

🐰 I hopped through tabs and checked each door,
Replaced raw calls with guards to keep them sure,
When content naps, I gently step aside,
No crash shall wake — the app can calmly glide,
A tiny patch, a safer, softer stride.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding null-safety guards to prevent tab access crashes when content is null.
Description check ✅ Passed The description is directly related to the changeset, explaining the null-safety guards added to prevent NullPointerException issues when content is unavailable after activity destruction.

✏️ 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 fix/ADFA-3030-null-content-tab-access

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.

@jatezzz jatezzz force-pushed the fix/ADFA-3030-null-content-tab-access branch from 2eb01b0 to 5dd5c9b Compare February 26, 2026 21:48
Copy link
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt`:
- Around line 554-556: The code returns 0 when contentOrNull is null (in
EditorHandlerActivity functions such as where safeContent is assigned and in
openFileAndGetIndex), which treats teardown as a valid tab index; change the
early-return value to a sentinel invalid index (e.g., -1) instead of 0, and
update all similar guards (the block around safeContent and the similar guard at
lines 558-564) so callers can detect and ignore the teardown case; ensure any
call sites that expect an index now treat negative values as "not
found"/teardown and avoid dereferencing content when the sentinel is returned.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2eb01b0 and 5dd5c9b.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt

Copy link
Collaborator

@hal-eisen-adfa hal-eisen-adfa left a comment

Choose a reason for hiding this comment

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

LGTM

@jatezzz jatezzz merged commit 34f24db into stage Mar 3, 2026
2 checks passed
@jatezzz jatezzz deleted the fix/ADFA-3030-null-content-tab-access branch March 3, 2026 14:12
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