Tencent/matrix · error · ProcStatUtil.ParseException
Couldn't read number!
Error message
Couldn't read number!
What it means
ProcStatReader.readNumber() accumulates digits into a number; if the first character is neither a digit nor '-' it cannot parse a numeric token and throws ParseException("Couldn't read number!"). Called by jiffies(), it means the expected utime/stime numeric field did not start with a number.
Solutions
- Catch ParseException and skip this sampling round, then retry next tick.
- Verify field alignment: ensure comm (in parentheses, possibly containing spaces/digits) is consumed correctly before reading utime/stime.
- Use ProcStatUtil.parseWithBuffer which tokenizes from the raw byte array and handles the comm field explicitly.
- Sanity-check the raw /proc/<pid>/stat line on the failing device.
Example fix
// before
long jiffies = ProcStatUtil.instance.jiffies(pid, true);
// after
Long jiffies = null;
try {
jiffies = ProcStatUtil.instance.jiffies(pid, true);
} catch (ProcStatUtil.ParseException e) {
// skip malformed sample
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify stat line field alignment after comm
String line = readStatLine(pid);
int close = line.lastIndexOf(')');
String[] rest = line.substring(close + 2).trim().split("\\s+");
boolean ok = rest.length >= 2 && rest[11].matches("\\d+"); // utime at index 11 after state Try / catch
try { long j = ProcStatUtil.instance.jiffies(pid, true); } catch (ProcStatUtil.ParseException e) { j = -1; /* skip */ } Prevention
- Ensure comm is parsed via parentheses, not whitespace splitting
- Validate one stat line format per device before enabling sampling
- Catch ParseException per-pid inside the sampling loop
- Update Matrix if stat layout errors recur on specific kernels
When it happens
Trigger: Calling jiffies() when the current position lands on a non-digit, non-'-' character on the first iteration - e.g. field offsets shifted by an unusual comm value or an unexpected stat layout.
Common situations: Kernel variations or emulators where field ordering differs; a prior mis-parse of the parenthesized process name (comm) leaving the reader positioned inside text.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Can only rewind one step!
- Couldn't read string!
- Couldn't read number because the file ended!
- utime
- stime
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/e87af6a78c6c7b18.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/ProcStatReader.java:175
buffer.flip();
return buffer;
}
public long readNumber() {
long sign = 1;
long result = 0;
boolean isFirstRun = true;
while (hasNext()) {
next();
if (Character.isDigit(mChar)) {
result = result * 10 + (mChar - '0');
} else if (isFirstRun) {
if (mChar == '-') {
sign = -1;
} else {
throw new ParseException("Couldn't read number!");
}
} else {
rewind();
break;
}
isFirstRun = false;
}
if (isFirstRun) {
throw new ParseException("Couldn't read number because the file ended!");
}
return sign * result;
}
public CharBuffer readToSymbol(char symbol, CharBuffer buffer) {
buffer.clear();View on GitHub (pinned to 3b8293bd65)