Skip to content

ADFA-5363: Initialize Termux properties when TermuxService is created first - #2128

Open
Daniel-ADFA wants to merge 1 commit into
stagefrom
fix/ADFA-5363-termux-properties-npe
Open

Daniel-ADFA wants to merge 1 commit into
stagefrom
fix/ADFA-5363-termux-properties-npe

Conversation

@Daniel-ADFA

@Daniel-ADFA Daniel-ADFA commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-5363

Fixes the fatal NullPointerException in TermuxService.createTermuxSession() (GlitchTip CODEONTHEGO-7G, 18 events, still on C-r-1006).

  • TermuxService.onCreate() gets the properties with TermuxAppSharedProperties.init() instead of getProperties(). When the service is created before the async TermuxApplicationLoader has run, getProperties() was null and stayed null in mProperties. Same fix ADFA-4330 made for TermuxShellManager two lines below.
  • TermuxAppSharedProperties.init() is synchronized and the field volatile, since the service and the loader can now both call it at startup.
  • TermuxServicePropertiesNpeTest fails without the fix.

Other getProperties() readers: TermuxShellUtils.clearTermuxTMPDIR() is only called from TermuxService.onDestroy(), covered here; TermuxPluginUtils null-checks; TermuxAmSocketServer and FileReceiverActivity run after an init().

Reproduce (debug build, jdb)
  1. Open a project and stay in the editor, without having opened the Terminal in this process.
  2. adb forward tcp:8700 jdwp:$(adb shell pidof com.itsaky.androidide) and jdb -attach localhost:8700
  3. stop in com.termux.app.TermuxService.onCreate, then open the Terminal from the drawer.
  4. On the breakpoint: set com.termux.shared.termux.settings.properties.TermuxAppSharedProperties.properties = null, clear com.termux.app.TermuxService.onCreate, cont.
  5. Before: the app crashes with the GlitchTip stack. After: the Terminal opens a session.

… first

TermuxService.onCreate() copied TermuxAppSharedProperties.getProperties()
into mProperties. The singleton is created by TermuxApplicationLoader, which
runs asynchronously after the process starts, so a service created before it
kept a null mProperties and the first createTermuxSession() threw a
NullPointerException (GlitchTip CODEONTHEGO-7G, up to C-r-1006).

Use init(), which returns the loaded instance or loads it, as onCreate()
already does for TermuxShellManager (ADFA-4330). init() is now synchronized
and the field volatile, because the service and the startup loader can both
call it during startup and must share one instance.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: fd21559c-cd6c-4042-8c33-2fd251fc8497

📥 Commits

Reviewing files that changed from the base of the PR and between dbeb7b2 and 1f2b31b.


📒 Files selected for processing (3)
  • termux/termux-app/src/main/java/com/termux/app/TermuxService.java
  • termux/termux-app/src/test/java/com/termux/app/TermuxServicePropertiesNpeTest.java
  • termux/termux-shared/src/main/java/com/termux/shared/termux/settings/properties/TermuxAppSharedProperties.java

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.



📝 Summary
  • TermuxService.onCreate() now calls TermuxAppSharedProperties.init() so the service can initialize shared properties before the application loader runs.
  • TermuxAppSharedProperties.init() is synchronized, and the properties field is volatile, to coordinate initialization across threads.
  • Added Robolectric tests for service creation before and after loader initialization.
  • Validation: Test results and current review findings were not provided, so their status is unknown.

Walkthrough

TermuxService now initializes shared properties with the application context. The shared properties singleton uses a volatile field and synchronized initialization. Robolectric tests cover service creation before and after the singleton is initialized.

Changes

Service properties initialization

Layer / File(s) Summary
Shared properties singleton initialization
termux/termux-shared/src/main/java/com/termux/shared/termux/settings/properties/TermuxAppSharedProperties.java
The properties field is now volatile, and init(Context) is synchronized. Lazy initialization remains unchanged.
Service initialization and tests
termux/termux-app/src/main/java/com/termux/app/TermuxService.java, termux/termux-app/src/test/java/com/termux/app/TermuxServicePropertiesNpeTest.java
TermuxService.onCreate() calls init() with the application context. Tests check the service properties when the singleton is null and when it is already initialized.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 1f2b3

Service startup now initializes shared properties before session use, and concurrent loader initialization reuses the fully constructed instance. No merge-blocking issue is established.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description clearly explains the Termux properties initialization fix, the startup race, the resulting NullPointerException, and the added regression test.
Title check Passed The title clearly and concisely identifies the primary change: initializing Termux properties when TermuxService is created first.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the service’s start,
And finds its properties in part.
The singleton waits, then wakes,
With synchronized care it makes.
Two tests confirm the instance stays.

Comment @coderabbitai help to get the list of available commands.

@Daniel-ADFA
Daniel-ADFA requested a review from a team October 11, 2026 20:07
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