Skip to content

ADFA-4326: Guard uninitialized projectPath on process-death recreation#1414

Open
fryanpan wants to merge 3 commits into
stagefrom
ADFA-4326-editoractivity-uninitialized-projectpath
Open

ADFA-4326: Guard uninitialized projectPath on process-death recreation#1414
fryanpan wants to merge 3 commits into
stagefrom
ADFA-4326-editoractivity-uninitialized-projectpath

Conversation

@fryanpan

@fryanpan fryanpan commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Jira Ticket: https://appdevforall.atlassian.net/browse/ADFA-4326
Sentry Issue: https://appdevforall-inc-9p.sentry.io/issues/APPDEVFORALL-QZ

Reproduction Details

After process death the OS can recreate EditorActivity without routing through MainActivity, leaving ProjectManagerImpl's lateinit projectPath unset. EditorActivity reads projectDirPath during onCreate (via EditorViewModel.getProjectName → projectDir → projectDirPath); the getter delegated straight to the lateinit and threw UninitializedPropertyAccessException, failing activity start.

Stack Trace

RuntimeException: Unable to start activity ComponentInfo{….EditorActivityKt}:
  kotlin.UninitializedPropertyAccessException: lateinit property projectPath has not been initialized
    at com.itsaky.androidide.projects.ProjectManagerImpl.getProjectPath(SourceFile:7)
    at com.itsaky.androidide.projects.ProjectManagerImpl.getProjectDirPath(SourceFile)
    at com.itsaky.androidide.viewmodel.EditorViewModel.getProjectName(SourceFile:6)
    at com.itsaky.androidide.activities.editor.BaseEditorActivity.onCreate(SourceFile:159)
    at com.itsaky.androidide.activities.editor.ProjectHandlerActivity.onCreate(...)
    at com.itsaky.androidide.activities.editor.EditorHandlerActivity.onCreate(SourceFile:8)

User Steps

User steps leading up to crash, based on Sentry breadcrumbs:

  • The process was recreated while the device was still locked (breadcrumb: BaseApplication: Creating safe context because user is not unlocked → direct-boot / credential-protected storage), then EditorActivity/EditorSidebarFragment are recreated with no project context → crash on first projectPath access.

Was able to reproduce in a unit test?

Yes.
ProjectManagerImplUninitializedPathTest (:subprojects:projects, Robolectric) constructs a fresh ProjectManagerImpl (projectPath never set = the process-death state) and reads projectDirPath/projectDir. Baseline: 2/3 cases FAIL with UninitializedPropertyAccessException (the 3rd, initialized, passes — not a tautology). Branch: 3/3 pass.

What Was Fixed

Guarded getter — get() = if (this::projectPath.isInitialized) projectPath else "" — and EditorViewModel/BaseEditorActivity route back to MainActivity instead of crashing when there's no project context.

Testing

:subprojects:projects:testV8DebugUnitTest → 3/3 green (red on baseline). Local CodeRabbit review: no findings. Reviewer notes (local): the finish()+return only exits BaseEditorActivity.onCreate — subclass onCreate (services/LSP/initializeProject) still runs on the finishing activity; consider short-circuiting earlier / isFinishing guards. The EditorViewModel blank-path guard is redundant with the getter fix. Recommend an android-qa smoke of the process-death → editor-recreation path before close.


Fixes APPDEVFORALL-QZ

@fryanpan fryanpan marked this pull request as ready for review June 19, 2026 11:21
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@fryanpan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 27 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 29dfe321-9c4e-4228-9a9c-b71a1b13c9cb

📥 Commits

Reviewing files that changed from the base of the PR and between d73ec0b and ea4b254.

📒 Files selected for processing (4)
  • app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt
  • app/src/main/java/com/itsaky/androidide/viewmodel/EditorViewModel.kt
  • subprojects/projects/src/main/java/com/itsaky/androidide/projects/ProjectManagerImpl.kt
  • subprojects/projects/src/test/java/com/itsaky/androidide/projects/ProjectManagerImplUninitializedPathTest.kt
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ADFA-4326-editoractivity-uninitialized-projectpath

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.

fryanpan and others added 3 commits June 19, 2026 09:58
Sentry APPDEVFORALL-QZ. Restore ProjectManagerImpl.projectPath from
savedInstanceState -> intent PROJECT_PATH extra -> lastOpenedProject;
guard projectDirPath getter; route back to MainActivity if still unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds ProjectManagerImplUninitializedPathTest covering the root cause of the
EditorActivity crash after process-death recreation: reading
ProjectManagerImpl.projectDirPath while the lateinit projectPath is unset.

Pre-fix the getter delegated directly to the lateinit (get() = projectPath),
throwing UninitializedPropertyAccessException; the fix guards with
isInitialized and returns "" so the caller can route back to MainActivity.

The test fails (UninitializedPropertyAccessException) on the pre-fix baseline
and passes on the fix branch. A third case asserts the getter still reflects an
assigned path, guarding against an always-blank regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fryanpan fryanpan force-pushed the ADFA-4326-editoractivity-uninitialized-projectpath branch from c2b5184 to ea4b254 Compare June 19, 2026 16:58
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