Skip to content

fix(ADFA-2551): check binding is alive before writing to output#825

Merged
dara-abijo-adfa merged 3 commits intostagefrom
ADFA-2551-illegal-state-exception
Jan 16, 2026
Merged

fix(ADFA-2551): check binding is alive before writing to output#825
dara-abijo-adfa merged 3 commits intostagefrom
ADFA-2551-illegal-state-exception

Conversation

@dara-abijo-adfa
Copy link
Contributor

Check if binding is null before accessing its content

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough
  • Changes

    • BaseEditorActivity.binding: Replaced get() = checkNotNull(_binding) { "Activity has been destroyed" } with get() = _binding ?: throw IllegalStateException("Activity destroyed; binding not accessible") — explicit null-coalescing guard and a direct IllegalStateException when accessed after destruction.
    • ProjectHandlerActivity.appendBuildOutput(str: String): Added an early-return guard: if (_binding == null || isDestroyed || isFinishing) return — prevents UI access when the activity or binding is not valid.
  • Risk Assessment & Best Practices

    • ⚠️ Exception type/message change: The binding getter now throws IllegalStateException instead of the exception produced by checkNotNull. Code that relied on the previous exception type/message (e.g., specific catch blocks or error parsing) may need updates.
    • ⚠️ Partial defensive coverage: appendBuildOutput is now guarded, but many call sites (e.g., onBackPressed callback and other methods in BaseEditorActivity) still access binding/content without null checks. Consider auditing all uses of _binding/binding and centralizing safe access patterns (e.g., scoped safe-binding usage or lifecycle-aware helpers).
    • ⚠️ Potential consistency issue: The change makes null access failure explicit but still leaves UI-call sites that assume binding is always available; mixing direct throws and early returns can lead to inconsistent behavior across lifecycle races.
    • ✓ Positive: Early-return guard in appendBuildOutput avoids unsafe UI updates and potential crashes when build output arrives during teardown.
    • ✓ Positive: Explicit IllegalStateException makes the failure mode clearer when binding is accessed after destruction.
  • Recommendations

    • Audit all methods in BaseEditorActivity and subclasses for direct binding/content access; add guards or use a single helper to access binding safely.
    • If callers expect a throwable type, update exception handling to catch IllegalStateException where appropriate.
    • Consider using a lifecycle-aware pattern (e.g., requireBinding() helper that documents behavior) to standardize handling across the codebase.

Walkthrough

Updated null-safety around activity view binding in two editor activities: the binding getter now throws IllegalStateException when underlying reference is null, and appendBuildOutput now returns early if binding is unavailable or the activity is finishing/destroyed.

Changes

Cohort / File(s) Summary
Binding getter change
app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt
Replaced checkNotNull(_binding) { "Activity has been destroyed" } with _binding ?: throw IllegalStateException("Activity destroyed; binding not accessible") — changes runtime exception type/message when accessed after destruction.
Early-return guard in UI method
app/src/main/java/com/itsaky/androidide/activities/editor/ProjectHandlerActivity.kt
Added guard in appendBuildOutput to return early when _binding is null or activity is destroyed/finishing to avoid unsafe UI access and potential NPEs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • itsaky-adfa
  • Daniel-ADFA

Poem

🐰 I hopped to check a binding tight,
If activity's gone, don't cause a fright.
Throw with care, return when nil,
Keep UI calm and all is chill. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a binding null check before accessing output content to prevent exceptions.
Description check ✅ Passed The description directly relates to the changeset, stating the core intent to check if binding is null before accessing its content.
Linked Issues check ✅ Passed The PR title references ADFA-2551, indicating a linked issue that contextualizes the binding null-check fix being implemented.
Out of Scope Changes check ✅ Passed All changes are scoped to binding null-safety fixes in BaseEditorActivity and ProjectHandlerActivity, directly addressing the PR objectives.

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

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7336def and bc36313.

📒 Files selected for processing (2)
  • app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt
  • app/src/main/java/com/itsaky/androidide/activities/editor/ProjectHandlerActivity.kt
🔇 Additional comments (2)
app/src/main/java/com/itsaky/androidide/activities/editor/ProjectHandlerActivity.kt (1)

371-374: LGTM!

The guard correctly prevents IllegalStateException and potential NPE by returning early when the binding is unavailable or the activity lifecycle has progressed beyond a safe state. The check order is appropriate with null check first for short-circuit evaluation.

app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt (1)

191-192: LGTM!

The change is functionally equivalent to the previous checkNotNull approach—both throw IllegalStateException when _binding is null. The explicit throw makes the behavior clearer and aligns with the guard pattern introduced in ProjectHandlerActivity.appendBuildOutput.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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
Copy link
Contributor Author

@coderabbitai

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

Tip

For best results, initiate chat on the files or code changes.

@dara-abijo-adfa, hello! How can I assist you with this PR? I can help with:

  • Reviewing the changes in detail
  • Answering questions about the implementation
  • Suggesting improvements or alternatives
  • Generating tests
  • Creating documentation
  • Or anything else related to this pull request

Please let me know what you'd like me to do!

@dara-abijo-adfa dara-abijo-adfa merged commit 4550221 into stage Jan 16, 2026
2 checks passed
@dara-abijo-adfa dara-abijo-adfa deleted the ADFA-2551-illegal-state-exception branch January 16, 2026 13:09
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.

3 participants

Comments