MuntashirAkon/AppManager · error · java.lang.IllegalArgumentException
tv_nsec value is not in [0, 999999999]
Error message
tv_nsec value ${tv_nsec} is not in [0, 999999999] What it means
The StructTimespec constructor validates that tv_nsec is a nanosecond field within [0, 999999999], unless it is one of the special kernel values UTIME_OMIT or UTIME_NOW. Any other out-of-range nanosecond value is rejected with an IllegalArgumentException.
Solutions
- Clamp or correctly convert the value: nanoseconds = (millis % 1000) * 1_000_000, seconds = millis / 1000.
- Verify the tv_nsec value is in [0, 999999999] before constructing.
- Use the exact OsCompat.UTIME_NOW / OsCompat.UTIME_OMIT constants for sentinel semantics rather than hand-picked numbers.
Example fix
// before new StructTimespec(millis / 1000, millis * 1_000_000_000); // out of range // after new StructTimespec(millis / 1000, (millis % 1000) * 1_000_000);
Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidTvNsec(long tv_nsec) {
return tv_nsec == OsCompat.UTIME_OMIT || tv_nsec == OsCompat.UTIME_NOW
|| (tv_nsec >= 0 && tv_nsec <= 999_999_999);
} Try / catch
try {
new StructTimespec(sec, nsec);
} catch (IllegalArgumentException e) {
// normalize nsec into [0, 999999999] and retry
} Prevention
- Split timestamps as seconds = total/1e9 (or /1000 for ms) and nanos = remainder.
- Never put a full duration into the nanoseconds field.
- Use the exact UTIME_NOW / UTIME_OMIT constants for sentinel values.
When it happens
Trigger: Constructing new StructTimespec(tv_sec, tv_nsec) where tv_nsec < 0 or tv_nsec > 999999999 and it is not exactly OsCompat.UTIME_OMIT or OsCompat.UTIME_NOW.
Common situations: Converting milliseconds/microseconds to nanoseconds with the wrong multiplier (e.g. ms * 1_000_000_000); passing a full timestamp in the nanoseconds field; sign errors when converting negative durations; misusing UTIME sentinel constants with altered values.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Invalid key: for type
- Negative position
- Negative size
- Package name cannot be empty.
- Android System (android) cannot be backed up.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/cb22d06d52caba95.
Report an issue: GitHub.
Appendix: source
Thrown at libcore/compat/src/main/java/io/github/muntashirakon/compat/system/StructTimespec.java:30
public final class StructTimespec implements Comparable<StructTimespec> {
/**
* Seconds part of time of last data modification.
*/
public final long tv_sec; /*time_t*/
/**
* Nanoseconds (values are [0, 999999999]).
*/
public final long tv_nsec;
public StructTimespec(long tv_sec, long tv_nsec) {
this.tv_sec = tv_sec;
this.tv_nsec = tv_nsec;
if (tv_nsec == OsCompat.UTIME_OMIT || tv_nsec == OsCompat.UTIME_NOW) {
return;
}
if (tv_nsec < 0 || tv_nsec > 999_999_999) {
throw new IllegalArgumentException("tv_nsec value " + tv_nsec + " is not in [0, 999999999]");
}
}
@Override
public int compareTo(StructTimespec other) {
if (tv_sec > other.tv_sec) {
return 1;
}
if (tv_sec < other.tv_sec) {
return -1;
}
if (tv_nsec > other.tv_nsec) {
return 1;
}
if (tv_nsec < other.tv_nsec) {
return -1;
}
return 0;View on GitHub (pinned to 0152f468fc)