{"record":{"id":"2a72627ae52d294d","repo":"Tencent/matrix","slug":"unsupported-reference-type-value","errorCode":null,"errorMessage":"Unsupported reference type $value","messagePattern":"Unsupported reference type \\$value","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/MemoryUtil.kt","lineNumber":276,"sourceCode":"        val result = File(resultDir, \"result-${time}.tmp\")\n        return try {\n            result.apply {\n                createNewFile()\n            }\n        } catch (exception: IOException) {\n            error(\"Failed to create analyze result file on path ${result.absolutePath}.\")\n            null\n        }\n    }\n\n    private fun convertReferenceType(value: Int): ReferenceTraceElement.Type =\n        when (value) {\n            // It is an end-tag that can only be the last chain element reference type.\n            0 -> ReferenceTraceElement.Type.INSTANCE_FIELD\n            1 -> ReferenceTraceElement.Type.STATIC_FIELD\n            2 -> ReferenceTraceElement.Type.INSTANCE_FIELD\n            3 -> ReferenceTraceElement.Type.ARRAY_ENTRY\n            else -> throw IllegalArgumentException(\"Unsupported reference type $value\")\n        }\n\n    private fun convertObjectType(value: Int): ReferenceTraceElement.Holder =\n        when (value) {\n            1 -> ReferenceTraceElement.Holder.CLASS\n            2 -> ReferenceTraceElement.Holder.ARRAY\n            3 -> ReferenceTraceElement.Holder.OBJECT\n            else -> throw IllegalArgumentException(\"Unsupported object type $value\")\n        }\n\n    private data class LeakChain(val nodes: List<Node>) {\n        data class Node(\n            val objectName: String,\n            val objectType: Int,\n            val referenceName: String,\n            val referenceType: Int\n        )\n","sourceCodeStart":258,"sourceCodeEnd":294,"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/MemoryUtil.kt#L258-L294","documentation":"MemoryUtil.convertReferenceType maps numeric reference-type codes from the leak-chain hprof data to ReferenceTraceElement.Type. When the code is outside {0,1,2,3}, it throws IllegalArgumentException('Unsupported reference type $value'), indicating corrupted or newer-format hprof data the parser doesn't understand.","triggerScenarios":"Parsing an hprof/leak-chain file whose reference chain node contains a type byte other than 0 (end-tag/instance field), 1 (static field), 2 (instance field), or 3 (array entry).","commonSituations":"Hprof files generated by newer JVM/ART versions with new reference kinds; truncated or corrupted dump files; manually edited or third-party-produced hprof files fed into Matrix's analyzer.","solutions":["Re-capture the hprof with a device/ART version supported by your Matrix version.","Upgrade matrix-resource-canary to the latest release so newer reference types are supported.","Validate the hprof file integrity (re-dump) if corruption is suspected.","Wrap parsing in a try-catch for IllegalArgumentException and skip the offending chain if the input is untrusted."],"exampleFix":"// before\nMemoryUtil.parse(hprofFile) // hprof from unsupported/newer ART\n// after\ntry {\n  MemoryUtil.parse(hprofFile)\n} catch (e: IllegalArgumentException) {\n  MatrixLog.e(TAG, \"skip unsupported hprof: ${e.message}\")\n  hprofFile.delete()\n}","handlingStrategy":"try-catch","validationCode":"fun isKnownReferenceType(v: Int) = v in 0..3","typeGuard":"fun Int.asReferenceType(): ReferenceTraceElement.Type? = when (this) {\n  0, 2 -> ReferenceTraceElement.Type.INSTANCE_FIELD\n  1 -> ReferenceTraceElement.Type.STATIC_FIELD\n  3 -> ReferenceTraceElement.Type.ARRAY_ENTRY\n  else -> null\n}","tryCatchPattern":"try {\n  MemoryUtil.parse(hprofFile)\n} catch (e: IllegalArgumentException) {\n  MatrixLog.e(TAG, \"unsupported/corrupt hprof: ${e.message}\")\n  hprofFile.delete()\n}","preventionTips":["Keep Matrix resource-canary updated to match device ART dump formats.","Only parse hprof files produced by the same or compatible Matrix versions.","Treat user-supplied dumps as untrusted; always catch IllegalArgumentException during parsing."],"tags":["android","hprof","memory-leak","unsupported-value"],"backgroundTag":"unsupported-enum-value","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"}