Tencent/matrix · error · IllegalArgumentException

Unsupported reference type $value

Error message

Unsupported reference type $value

What it means

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.

Solutions

  1. Re-capture the hprof with a device/ART version supported by your Matrix version.
  2. Upgrade matrix-resource-canary to the latest release so newer reference types are supported.
  3. Validate the hprof file integrity (re-dump) if corruption is suspected.
  4. Wrap parsing in a try-catch for IllegalArgumentException and skip the offending chain if the input is untrusted.

Example fix

// before
MemoryUtil.parse(hprofFile) // hprof from unsupported/newer ART
// after
try {
  MemoryUtil.parse(hprofFile)
} catch (e: IllegalArgumentException) {
  MatrixLog.e(TAG, "skip unsupported hprof: ${e.message}")
  hprofFile.delete()
}
Defensive patterns

Strategy: try-catch

Validate before calling

fun isKnownReferenceType(v: Int) = v in 0..3

Type guard

fun Int.asReferenceType(): ReferenceTraceElement.Type? = when (this) {
  0, 2 -> ReferenceTraceElement.Type.INSTANCE_FIELD
  1 -> ReferenceTraceElement.Type.STATIC_FIELD
  3 -> ReferenceTraceElement.Type.ARRAY_ENTRY
  else -> null
}

Try / catch

try {
  MemoryUtil.parse(hprofFile)
} catch (e: IllegalArgumentException) {
  MatrixLog.e(TAG, "unsupported/corrupt hprof: ${e.message}")
  hprofFile.delete()
}

Prevention

When it happens

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

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

Related errors


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

Appendix: source

Thrown at matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/MemoryUtil.kt:276

        val result = File(resultDir, "result-${time}.tmp")
        return try {
            result.apply {
                createNewFile()
            }
        } catch (exception: IOException) {
            error("Failed to create analyze result file on path ${result.absolutePath}.")
            null
        }
    }

    private fun convertReferenceType(value: Int): ReferenceTraceElement.Type =
        when (value) {
            // It is an end-tag that can only be the last chain element reference type.
            0 -> ReferenceTraceElement.Type.INSTANCE_FIELD
            1 -> ReferenceTraceElement.Type.STATIC_FIELD
            2 -> ReferenceTraceElement.Type.INSTANCE_FIELD
            3 -> ReferenceTraceElement.Type.ARRAY_ENTRY
            else -> throw IllegalArgumentException("Unsupported reference type $value")
        }

    private fun convertObjectType(value: Int): ReferenceTraceElement.Holder =
        when (value) {
            1 -> ReferenceTraceElement.Holder.CLASS
            2 -> ReferenceTraceElement.Holder.ARRAY
            3 -> ReferenceTraceElement.Holder.OBJECT
            else -> throw IllegalArgumentException("Unsupported object type $value")
        }

    private data class LeakChain(val nodes: List<Node>) {
        data class Node(
            val objectName: String,
            val objectType: Int,
            val referenceName: String,
            val referenceType: Int
        )

View on GitHub (pinned to 3b8293bd65)