{"record":{"id":"bcd6c07b1e950967","repo":"Tencent/matrix","slug":"statbuffer-utime-num","errorCode":null,"errorMessage":"${statBuffer}\nutime: ${num}","messagePattern":"(.+?)\nutime: (.+?)","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/ProcStatUtil.java","lineNumber":235,"sourceCode":"                    // seek next space\n                    while (i < statBytes && !Character.isSpaceChar(statBuffer[i])) {\n                        i++;\n                        window++;\n                    }\n                    stat.stat = safeBytesToString(statBuffer, readIdx, window);\n                    break;\n                }\n\n                case 14: { // utime\n                    int readIdx = i, window = 0;\n                    // seek next space\n                    while (i < statBytes && !Character.isSpaceChar(statBuffer[i])) {\n                        i++;\n                        window++;\n                    }\n                    String num = safeBytesToString(statBuffer, readIdx, window);\n                    if (!isNumeric(num)) {\n                        throw new ParseException(safeBytesToString(statBuffer, 0, statBuffer.length) + \"\\nutime: \" + num);\n                    }\n                    stat.utime = MatrixUtil.parseLong(num, 0);\n                    break;\n                }\n                case 15: { // stime\n                    int readIdx = i, window = 0;\n                    // seek next space\n                    while (i < statBytes && !Character.isSpaceChar(statBuffer[i])) {\n                        i++;\n                        window++;\n                    }\n                    String num = safeBytesToString(statBuffer, readIdx, window);\n                    if (!isNumeric(num)) {\n                        throw new ParseException(safeBytesToString(statBuffer, 0, statBuffer.length) + \"\\nstime: \" + num);\n                    }\n                    stat.stime = MatrixUtil.parseLong(num, 0);\n                    break;\n                }","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/ProcStatUtil.java#L217-L253","documentation":"ProcStatUtil.parseWithBuffer tokenizes the /proc/<pid>/stat byte array field-by-field; for field 14 (utime) it extracts the token and validates it with isNumeric(). If the token is not numeric it throws ParseException containing the whole stat line plus \"utime: <token>\", because assigning a non-numeric utime would corrupt CPU-time accounting.","triggerScenarios":"Field 14 of the stat line does not parse as a number - usually the comm field contained spaces/digits shifting token positions, or the buffer was truncated mid-field.","commonSituations":"Processes whose names contain spaces or digits (comm not correctly bracketed), emulators/vendor kernels with unusual stat layout, partially read buffers.","solutions":["Catch ParseException, log the embedded raw stat line (the message contains it), and skip this sample.","Verify comm handling: the parser must skip the parenthesized name including any spaces/digits before counting fields.","Use the embedded stat content in the message to diagnose the exact misalignment on the failing device.","Update Matrix or patch parseWithBuffer to locate utime/stime relative to the last ')' instead of counting fields."],"exampleFix":"// before\nStatModel stat = ProcStatUtil.instance.parseWithBufferForPath(path);\n// after\ntry {\n    StatModel stat = ProcStatUtil.instance.parseWithBufferForPath(path);\n} catch (ProcStatUtil.ParseException e) {\n    Log.w(TAG, \"bad stat line: \" + e.getMessage()); // message contains raw buffer\n}","handlingStrategy":"try-catch","validationCode":"String line = readStatLine(pid);\nint close = line.lastIndexOf(')');\nString[] fields = line.substring(close + 2).trim().split(\"\\\\s+\");\nboolean utimeOk = fields.length > 11 && fields[11].matches(\"\\\\d+\");","typeGuard":null,"tryCatchPattern":"try { StatModel s = ProcStatUtil.instance.parseWithBufferForPath(path); } catch (ProcStatUtil.ParseException e) { Log.w(TAG, \"raw stat: \" + e.getMessage()); }","preventionTips":["Use the raw stat line embedded in the exception message to diagnose field shifts","Parse fields relative to the last ')' to be immune to odd comm values","Test with process names containing spaces and digits","Skip samples that fail numeric validation rather than defaulting values"],"tags":["android","proc-stat","utime","parser"],"backgroundTag":"invalid-argument-format","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}