{"record":{"id":"d99602f78db11275","repo":"Tencent/matrix","slug":"bad-value-type-value-getclass-getname","errorCode":null,"errorMessage":"bad value type: ${value.getClass().getName()}","messagePattern":"bad value type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/utils/IOUtil.java","lineNumber":264,"sourceCode":"            IOUtil.writeID(out, (ID) value);\n        } else if (value instanceof Boolean || boolean.class.isAssignableFrom(value.getClass())) {\n            out.write((boolean) value ? 1 : 0);\n        } else if (value instanceof Character || char.class.isAssignableFrom(value.getClass())) {\n            IOUtil.writeBEShort(out, (char) value);\n        } else if (value instanceof Float || float.class.isAssignableFrom(value.getClass())) {\n            IOUtil.writeBEInt(out, Float.floatToRawIntBits((Float) value));\n        } else if (value instanceof Double || double.class.isAssignableFrom(value.getClass())) {\n            IOUtil.writeBELong(out, Double.doubleToRawLongBits((Double) value));\n        } else if (value instanceof Byte || byte.class.isAssignableFrom(value.getClass())) {\n            out.write((byte) value);\n        } else if (value instanceof Short || short.class.isAssignableFrom(value.getClass())) {\n            IOUtil.writeBEShort(out, (short) value);\n        } else if (value instanceof Integer || int.class.isAssignableFrom(value.getClass())) {\n            IOUtil.writeBEInt(out, (int) value);\n        } else if (value instanceof Long || long.class.isAssignableFrom(value.getClass())) {\n            IOUtil.writeBELong(out, (long) value);\n        } else {\n            throw new IllegalArgumentException(\"bad value type: \" + value.getClass().getName());\n        }\n    }\n\n    public static void skip(OutputStream out, long size) throws IOException {\n        final byte[] emptyBuf = new byte[4096];\n        for (int i = 0; i < (size >> 12); ++i) {\n            out.write(emptyBuf);\n        }\n        out.write(emptyBuf, 0, (int) (size & ((1L << 12) - 1)));\n    }\n\n    private IOUtil() {\n        throw new UnsupportedOperationException();\n    }\n}\n","sourceCodeStart":246,"sourceCodeEnd":280,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/utils/IOUtil.java#L246-L280","documentation":"IOUtil.writeValue serializes a value to an hprof-backed output stream, supporting only Boolean, Character, Byte, Short, Integer and Long. If the value's runtime type is anything else (e.g. Float, Double, String, or an unexpected boxed object), it throws IllegalArgumentException. This is an internal type contract for hprof record value writing; the library only knows how to BE-encode those primitive widths.","triggerScenarios":"Calling HprofBufferWriter/IOUtil.writeValue (directly or via hprof record building in matrix-resource-canary) with a value whose class is not one of the supported wrapper types, e.g. passing a Float, Double, String or custom object where a primitive boxed value is expected.","commonSituations":"Custom hprof record construction or patched/forked code writing new record types with unsupported value types; version drift where a record format expects a type the writer doesn't handle; reflection-based value extraction returning an unexpected boxed type.","solutions":["Cast or convert the value to a supported type (Boolean, Character, Byte, Short, Integer, Long) before writing.","If the value is Float/Double, convert via Float.floatToIntBits / Double.doubleToLongBits and write as int/long.","For strings or complex data, use the hprof string/byte-array record APIs instead of writeValue.","Check the calling record-building code for a type-mapping bug introduced by recent changes."],"exampleFix":"// before\nIOUtil.writeValue(out, 3.14f);\n// after\nIOUtil.writeBEInt(out, Float.floatToIntBits(3.14f));","handlingStrategy":"validation","validationCode":"if (!(value instanceof Boolean || value instanceof Character || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long)) {\n    throw new IllegalArgumentException(\"Unsupported hprof value type: \" + value.getClass());\n}\nIOUtil.writeValue(out, value);","typeGuard":"static boolean isWritableHprofValue(Object v) {\n    return v instanceof Boolean || v instanceof Character || v instanceof Byte\n        || v instanceof Short || v instanceof Integer || v instanceof Long;\n}","tryCatchPattern":"try {\n    IOUtil.writeValue(out, value);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"Unsupported value type, skipping\", e);\n}","preventionTips":["Only pass boxed primitives from the supported set to writeValue","Convert floats/doubles with floatToIntBits/doubleToLongBits before writing","Use string/byte-array record APIs for non-primitive data"],"tags":["hprof","serialization","illegal-argument","type-mismatch"],"backgroundTag":"unsupported-dtype","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"}