{"record":{"id":"ee342571eae92e96","repo":"Tencent/matrix","slug":"could-not-find-char-array-in-instance","errorCode":null,"errorMessage":"Could not find char array in <instance>","messagePattern":"Could not find char array in <instance>","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer/src/main/java/com/squareup/haha/perflib/HahaHelper.java","lineNumber":121,"sourceCode":"            // In API 26, Strings are now internally represented as byte arrays.\n            array = (ArrayInstance) value;\n\n            // HACK - remove when HAHA's perflib is updated to https://goo.gl/Oe7ZwO.\n            try {\n                Method asRawByteArray =\n                        ArrayInstance.class.getDeclaredMethod(\"asRawByteArray\", int.class, int.class);\n                asRawByteArray.setAccessible(true);\n                byte[] rawByteArray = (byte[]) asRawByteArray.invoke(array, 0, count);\n                return new String(rawByteArray, Charset.forName(\"UTF-8\"));\n            } catch (NoSuchMethodException e) {\n                throw new RuntimeException(e);\n            } catch (IllegalAccessException e) {\n                throw new RuntimeException(e);\n            } catch (InvocationTargetException e) {\n                throw new RuntimeException(e);\n            }\n        } else {\n            throw new UnsupportedOperationException(\"Could not find char array in \" + instance);\n        }\n    }\n\n    public static boolean isPrimitiveWrapper(Object value) {\n        if (!(value instanceof ClassInstance)) {\n            return false;\n        }\n        return WRAPPER_TYPES.contains(((ClassInstance) value).getClassObj().getClassName());\n    }\n\n    public static boolean isPrimitiveOrWrapperArray(Object value) {\n        if (!(value instanceof ArrayInstance)) {\n            return false;\n        }\n        ArrayInstance arrayInstance = (ArrayInstance) value;\n        if (arrayInstance.getArrayType() != Type.OBJECT) {\n            return true;\n        }","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer/src/main/java/com/squareup/haha/perflib/HahaHelper.java#L103-L139","documentation":"HahaHelper.asString extracts a char[] from a heap dump instance (e.g. a java.lang.String) via reflection on the value field. If the reflected field does not contain a char array, the helper cannot convert the instance to a String and throws UnsupportedOperationException.","triggerScenarios":"threadName (or asString directly) is called on an instance whose backing field is not a char[] — e.g. a String stored as byte[] (compact strings on newer ART/JDK layouts) or the wrong field was matched by name.","commonSituations":"Parsing hprof dumps taken on newer Android versions where java.lang.String stores value as byte[] instead of char[]; corrupted heap dumps; dumps from device/ART versions the bundled Haha parser does not support.","solutions":["Update Matrix / the embedded Haha (or switch to LeakCanary's Shark parser) to a version supporting byte[]-backed Strings.","Re-capture the hprof on a device/OS combination known to work with the analyzer version in use.","In threadName, wrap asString in try-catch and fall back to a placeholder thread name instead of aborting analysis.","Verify the field actually holds a char[] before calling asString (check the ClassInstance field type)."],"exampleFix":"// before\nreturn asString(fieldValue(values, \"name\"));\n// after\nObject value = fieldValue(values, \"name\");\nif (value instanceof ArrayInstance) {\n    return asString(value);\n}\nreturn \"<unknown-thread>\";","handlingStrategy":"type-guard","validationCode":"Object v = fieldValue(values, \"value\");\nif (!(v instanceof ArrayInstance)) return \"<non-char-array string>\";","typeGuard":"boolean isCharArrayInstance(Object v) { return v instanceof ArrayInstance; }","tryCatchPattern":"try { return asString(instance); } catch (UnsupportedOperationException e) { return \"<unknown>\"; }","preventionTips":["Match analyzer version to the Android version producing dumps (byte[] compact strings)","Wrap asString calls with fallbacks in threadName","Prefer updated parsers (e.g. Shark) for modern dumps"],"tags":["hprof","heap-dump","android","reflection"],"backgroundTag":"type-mismatch","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"}