{"record":{"id":"347b9c84f115595e","repo":"Tencent/matrix","slug":"value-is-null","errorCode":null,"errorMessage":"value is null.","messagePattern":"value is null\\.","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":244,"sourceCode":"    }\n\n    public static void writeString(OutputStream out, String text) throws IOException {\n        final int length = text.length();\n        out.write(text.getBytes(Charset.forName(\"UTF-8\")), 0, length);\n    }\n\n    public static void writeNullTerminatedString(OutputStream out, String text) throws IOException {\n        out.write(text.getBytes(Charset.forName(\"UTF-8\")));\n        out.write(0);\n    }\n\n    public static void writeID(OutputStream out, ID id) throws IOException {\n        out.write(id.getBytes());\n    }\n\n    public static void writeValue(OutputStream out, Object value) throws IOException {\n        if (value == null) {\n            throw new IllegalArgumentException(\"value is null.\");\n        } else if (value instanceof ID) {\n            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);","sourceCodeStart":226,"sourceCodeEnd":262,"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#L226-L262","documentation":"IOUtil.writeValue() serializes a hprof primitive/ID value to an OutputStream but rejects null with IllegalArgumentException. Null is not representable in the hprof value encoding (every field has a concrete type and byte representation), so the caller must supply a typed value.","triggerScenarios":"Calling writeValue with a null Object when re-serializing hprof values; analysis code building synthetic class/instance dumps with unset fields; map iteration over values that contain null entries.","commonSituations":"Custom hprof rewriting/trimming tools built on hproflib that pass through unboxed values from collections containing nulls; deserialized models with missing primitive fields.","solutions":["Ensure every value passed to writeValue is non-null and of a supported type (ID, Boolean, Character, numeric).","Filter or substitute nulls before serialization (e.g. write Type.OBJECT null reference as an ID of 0).","Add an explicit null check at the call site with a descriptive error naming the field."],"exampleFix":"// before\nIOUtil.writeValue(out, fieldValue);\n\n// after\nif (fieldValue == null) {\n    // represent null reference as id 0\n    IOUtil.writeValue(out, new ID(new byte[idSize]));\n} else {\n    IOUtil.writeValue(out, fieldValue);\n}","handlingStrategy":"validation","validationCode":"static void requireWritableValue(Object v) {\n    if (v == null) throw new IllegalArgumentException(\"hprof value must be non-null; use ID(0) for null reference\");\n}","typeGuard":"static boolean isWritableValue(Object v) {\n    return v instanceof ID || v instanceof Boolean || v instanceof Character\n        || v instanceof Byte || v instanceof Short || v instanceof Integer\n        || v instanceof Long || v instanceof Float || v instanceof Double;\n}","tryCatchPattern":"try {\n    IOUtil.writeValue(out, value);\n} catch (IllegalArgumentException e) {\n    if (\"value is null.\".equals(e.getMessage())) {\n        IOUtil.writeValue(out, new ID(new byte[idSize])); // null reference\n    }\n}","preventionTips":["Never serialize raw map values without null-filtering","Represent null references as a zero ID matching the hprof idSize","Type-check values against supported hprof basic types before writing"],"tags":["hprof","null","serialization","android"],"backgroundTag":"null-argument","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"}