JobSchedulerAPI NullPointerException with --network none on Android 17
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start with JobSchedulerAPI.formatJobInfo() and reproduce the failure by scheduling a periodic job with --network none, then listing it with termux-job-scheduler --pending. Check how JobInfo.getRequiredNetwork() is formatted when it returns null, and handle that case without changing the scheduling behavior for jobs requiring a network. Done means both scheduling and listing a network-free job complete without an exception and display its information correctly.
Written by the indexing model from the issue text.
Description
Description
Termux:API 0.53.0 throws a NullPointerException when scheduling a job using termux-job-scheduler --network none.
The job appears to register successfully, but Termux:API crashes when formatting its information. Running termux-job-scheduler --pending subsequently produces the same exception.
Changing the network requirement to --network any resolves both errors.
Steps to Reproduce
-
Schedule a periodic job without a network requirement:
termux-job-scheduler \ --script "$HOME/dev/android-backup-cleanup/run.sh" \ --job-id 101 \ --period-ms 604800000 \ --persisted true \ --network none \ --battery-not-low true -
Observe the following exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.NetworkRequest.toString()' on a null object referenceat com.termux.api.apis.JobSchedulerAPI.formatJobInfo(SourceFile:57)
at com.termux.api.apis.JobSchedulerAPI.runScheduleJobAction(SourceFile:185)
-
List pending jobs:
termux-job-scheduler --pending -
Observe another exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.NetworkRequest.toString()' on a null object referenceat com.termux.api.apis.JobSchedulerAPI.formatJobInfo(SourceFile:57)
at com.termux.api.apis.JobSchedulerAPI.displayPendingJobs(SourceFile:253)
at com.termux.api.apis.JobSchedulerAPI.runDisplayPendingJobsAction(SourceFile:195)
-
Reschedule the same job with
--network any:termux-job-scheduler \ --script "$HOME/dev/android-backup-cleanup/run.sh" \ --job-id 101 \ --period-ms 604800000 \ --persisted true \ --network any \ --battery-not-low true -
Scheduling now succeeds, and
termux-job-scheduler --pendingcorrectly displays Job 101.
Expected Behavior
- Scheduling with
--network noneshould succeed without exceptions. termux-job-scheduler --pendingshould display jobs that do not require network connectivity.- A null network requirement should be handled gracefully.
Actual Behavior
- Scheduling with
--network nonethrows aNullPointerException. - Listing pending jobs also throws a
NullPointerException. - Using
--network anyprevents the crashes but unnecessarily requires network connectivity for offline jobs.
Suspected Cause
The stack trace points to JobSchedulerAPI.formatJobInfo() calling toString() on a null android.net.NetworkRequest.
Android's JobInfo.getRequiredNetwork() can return null when no network is required.
A null check before formatting the network requirement should prevent this exception.
Environment
| Component | Version |
|---|---|
| Device | Google Pixel 9 |
| Android | 17 (API 37) |
| Android build | CP3A.261005.005 |
| Security patch | 2026-10-05 |
| Termux | 0.118.3 |
| Termux:API | 0.53.0 |
| Installation source | F-Droid |
| Termux:API target SDK | 28 |
Workaround
Using --network any avoids the crash:
termux-job-scheduler --pending
This command successfully lists the registered job after rescheduling with --network any.
However, requiring network connectivity is unnecessary for jobs that operate entirely offline.
Additional Notes
The exception occurs while formatting job information rather than directly inside Android's job scheduling call.
The subsequent exception when listing pending jobs suggests the original job may have been registered, although that was not independently verified.
This appears to be a null-handling issue in Termux:API's JobScheduler response formatting.
- Dominant language
- Java
- Stars
- 4.5k
- Forks
- 969
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from termux/termux-api
-
Requesting Change System Settings permission failsPossibly taken @xJonathanLEI claimed this 187 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
termux/termux-api#864 · 1 comment ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
termux/termux-api#575 · 2 comments · 2 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
termux/termux-api#272 · 4 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
termux/termux-api#926 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
termux/termux-api#921 ·
All issues in termux/termux-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
aws/context-ontology-accelerator#325 ·
Maintainers usually reply within 1 day
-
The README tells to run `mvn jeo:disassemble`, which fails with `No plugin found for prefix 'jeo'`Open
Difficulty 1/5 Under an hour Newbie friendliness 82/100
objectionary/jeo-maven-plugin#1938 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
oVirt/ovirt-engine#1219 ·
Maintainers usually reply within 1 day
-
pending:code-area pending:issue-category to-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
area:core bug priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
aomarai/minecraft-mcp#247 ·
Maintainers usually reply within 1 day