{"record":{"id":"cb22d06d52caba95","repo":"MuntashirAkon/AppManager","slug":"tv-nsec-value-tv-nsec-is-not-in-0-999999999","errorCode":null,"errorMessage":"tv_nsec value ${tv_nsec} is not in [0, 999999999]","messagePattern":"tv_nsec value (.+?) is not in \\[0, 999999999\\]","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libcore/compat/src/main/java/io/github/muntashirakon/compat/system/StructTimespec.java","lineNumber":30,"sourceCode":"public final class StructTimespec implements Comparable<StructTimespec> {\n    /**\n     * Seconds part of time of last data modification.\n     */\n    public final long tv_sec; /*time_t*/\n\n    /**\n     * Nanoseconds (values are [0, 999999999]).\n     */\n    public final long tv_nsec;\n\n    public StructTimespec(long tv_sec, long tv_nsec) {\n        this.tv_sec = tv_sec;\n        this.tv_nsec = tv_nsec;\n        if (tv_nsec == OsCompat.UTIME_OMIT || tv_nsec == OsCompat.UTIME_NOW) {\n            return;\n        }\n        if (tv_nsec < 0 || tv_nsec > 999_999_999) {\n            throw new IllegalArgumentException(\"tv_nsec value \" + tv_nsec + \" is not in [0, 999999999]\");\n        }\n    }\n\n    @Override\n    public int compareTo(StructTimespec other) {\n        if (tv_sec > other.tv_sec) {\n            return 1;\n        }\n        if (tv_sec < other.tv_sec) {\n            return -1;\n        }\n        if (tv_nsec > other.tv_nsec) {\n            return 1;\n        }\n        if (tv_nsec < other.tv_nsec) {\n            return -1;\n        }\n        return 0;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/compat/src/main/java/io/github/muntashirakon/compat/system/StructTimespec.java#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew StructTimespec(millis / 1000, millis * 1_000_000_000); // out of range\n// after\nnew StructTimespec(millis / 1000, (millis % 1000) * 1_000_000);","handlingStrategy":"validation","validationCode":"static boolean isValidTvNsec(long tv_nsec) {\n    return tv_nsec == OsCompat.UTIME_OMIT || tv_nsec == OsCompat.UTIME_NOW\n        || (tv_nsec >= 0 && tv_nsec <= 999_999_999);\n}","typeGuard":null,"tryCatchPattern":"try {\n    new StructTimespec(sec, nsec);\n} catch (IllegalArgumentException e) {\n    // normalize nsec into [0, 999999999] and retry\n}","preventionTips":["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."],"tags":["time","validation","illegal-argument","nanoseconds"],"backgroundTag":"value-out-of-range","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}