Tencent/matrix · error · UnsupportedOperationException

Could not find char array in

Error message

Could not find char array in <instance>

What it means

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.

Solutions

  1. Update Matrix / the embedded Haha (or switch to LeakCanary's Shark parser) to a version supporting byte[]-backed Strings.
  2. Re-capture the hprof on a device/OS combination known to work with the analyzer version in use.
  3. In threadName, wrap asString in try-catch and fall back to a placeholder thread name instead of aborting analysis.
  4. Verify the field actually holds a char[] before calling asString (check the ClassInstance field type).

Example fix

// before
return asString(fieldValue(values, "name"));
// after
Object value = fieldValue(values, "name");
if (value instanceof ArrayInstance) {
    return asString(value);
}
return "<unknown-thread>";
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = fieldValue(values, "value");
if (!(v instanceof ArrayInstance)) return "<non-char-array string>";

Type guard

boolean isCharArrayInstance(Object v) { return v instanceof ArrayInstance; }

Try / catch

try { return asString(instance); } catch (UnsupportedOperationException e) { return "<unknown>"; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/ee342571eae92e96. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer/src/main/java/com/squareup/haha/perflib/HahaHelper.java:121

            // In API 26, Strings are now internally represented as byte arrays.
            array = (ArrayInstance) value;

            // HACK - remove when HAHA's perflib is updated to https://goo.gl/Oe7ZwO.
            try {
                Method asRawByteArray =
                        ArrayInstance.class.getDeclaredMethod("asRawByteArray", int.class, int.class);
                asRawByteArray.setAccessible(true);
                byte[] rawByteArray = (byte[]) asRawByteArray.invoke(array, 0, count);
                return new String(rawByteArray, Charset.forName("UTF-8"));
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        } else {
            throw new UnsupportedOperationException("Could not find char array in " + instance);
        }
    }

    public static boolean isPrimitiveWrapper(Object value) {
        if (!(value instanceof ClassInstance)) {
            return false;
        }
        return WRAPPER_TYPES.contains(((ClassInstance) value).getClassObj().getClassName());
    }

    public static boolean isPrimitiveOrWrapperArray(Object value) {
        if (!(value instanceof ArrayInstance)) {
            return false;
        }
        ArrayInstance arrayInstance = (ArrayInstance) value;
        if (arrayInstance.getArrayType() != Type.OBJECT) {
            return true;
        }

View on GitHub (pinned to 3b8293bd65)