Tencent/matrix · error · ParseException
stime
Error message
${statBuffer}
stime: ${num} What it means
Same validation as utime but for field 15 (stime) in ProcStatUtil.parseWithBuffer: the extracted token must pass isNumeric() or a ParseException with the full stat line and "stime: <token>" is thrown. It protects kernel-time (stime) accounting from garbage tokens.
Solutions
- Catch ParseException and skip the sample; the message includes the raw stat line for diagnosis.
- Fix comm-field consumption (parse fields relative to the final ')') so utime/stime land on the correct tokens.
- Compare the embedded stat line in the exception with the expected 52-field layout to find the offset.
- Update Matrix to a version with hardened stat parsing if available.
Example fix
// before
stat.stime = MatrixUtil.parseLong(num, 0);
// after
if (!isNumeric(num)) {
Log.w(TAG, "skip stat, bad stime token: " + num);
return null; // or throw as library does; callers should catch ParseException
}
stat.stime = MatrixUtil.parseLong(num, 0); Defensive patterns
Strategy: try-catch
Validate before calling
String line = readStatLine(pid);
int close = line.lastIndexOf(')');
String[] fields = line.substring(close + 2).trim().split("\\s+");
boolean stimeOk = fields.length > 12 && fields[12].matches("\\d+"); Try / catch
try { StatModel s = ProcStatUtil.instance.parseWithBufferForPath(path); } catch (ProcStatUtil.ParseException e) { if (e.getMessage().contains("stime:")) { /* log raw line, skip */ } } Prevention
- Validate both utime and stime tokens before consuming the stat
- Anchor field indices to the closing parenthesis of comm
- Keep the exception message (contains full stat line) in logs for diagnosis
- Pin a Matrix version with hardened stat parsing on affected kernels
When it happens
Trigger: Field 15 of the stat buffer is not numeric - token misalignment from a comm field containing spaces/digits, or a truncated/partial read of the stat file.
Common situations: Vendor kernel stat format differences; process names shifting field positions; the utime parse succeeded but the next token is misplaced text rather than a number.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/776777b40b82bfb6.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/ProcStatUtil.java:249
window++;
}
String num = safeBytesToString(statBuffer, readIdx, window);
if (!isNumeric(num)) {
throw new ParseException(safeBytesToString(statBuffer, 0, statBuffer.length) + "\nutime: " + num);
}
stat.utime = MatrixUtil.parseLong(num, 0);
break;
}
case 15: { // stime
int readIdx = i, window = 0;
// seek next space
while (i < statBytes && !Character.isSpaceChar(statBuffer[i])) {
i++;
window++;
}
String num = safeBytesToString(statBuffer, readIdx, window);
if (!isNumeric(num)) {
throw new ParseException(safeBytesToString(statBuffer, 0, statBuffer.length) + "\nstime: " + num);
}
stat.stime = MatrixUtil.parseLong(num, 0);
break;
}
case 16: { // cutime
int readIdx = i, window = 0;
// seek next space
while (i < statBytes && !Character.isSpaceChar(statBuffer[i])) {
i++;
window++;
}
String num = safeBytesToString(statBuffer, readIdx, window);
if (!isNumeric(num)) {
throw new ParseException(safeBytesToString(statBuffer, 0, statBuffer.length) + "\ncutime: " + num);
}
stat.cutime = MatrixUtil.parseLong(num, 0);
break;
}View on GitHub (pinned to 3b8293bd65)