Tencent/matrix · error · IllegalArgumentException

config.delayMillis is empty

Error message

config.delayMillis is empty

What it means

TrimMemoryNotifier.init throws IllegalArgumentException when the supplied TrimMemoryConfig has enable=true but an empty delayMillis list. The notifier schedules trim-memory notifications at each delay in that list, so an empty list makes the component unusable and it fails fast during init.

Solutions

  1. Provide at least one value in delayMillis, e.g. longArrayOf(500, 1000, 3000).
  2. Or set enable=false so init returns early without validation.
  3. Add a default fallback in code: if (config.delayMillis.isEmpty()) use default delays before calling init.

Example fix

// before
val config = TrimMemoryConfig(enable = true, delayMillis = emptyList())
TrimMemoryNotifier.init(config)
// after
val config = TrimMemoryConfig(enable = true, delayMillis = listOf(500L, 1000L, 3000L))
TrimMemoryNotifier.init(config)
Defensive patterns

Strategy: validation

Validate before calling

fun safeInit(raw: TrimMemoryConfig): Boolean {
  if (!raw.enable) return false
  if (raw.delayMillis.isNullOrEmpty()) {
    MatrixLog.e("Trim", "delayMillis empty; using defaults")
    TrimMemoryNotifier.init(TrimMemoryConfig(true, listOf(500L, 1000L, 3000L)))
    return true
  }
  TrimMemoryNotifier.init(raw)
  return true
}

Type guard

fun isValidTrimConfig(c: TrimMemoryConfig): Boolean = !c.enable || c.delayMillis.isNotEmpty()

Try / catch

try {
  TrimMemoryNotifier.init(config)
} catch (e: IllegalArgumentException) {
  MatrixLog.e(TAG, "invalid TrimMemoryConfig: ${e.message}")
}

Prevention

When it happens

Trigger: Constructing a TrimMemoryConfig with enable=true and leaving delayMillis empty (or empty array/list via JSON/dynamic config), then calling TrimMemoryNotifier.init(config).

Common situations: Server-driven / dynamic config returning an empty delay array; copying a config template where delayMillis was never filled; type changes turning the list into an empty default.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at matrix/matrix-android/matrix-memory-canary/src/main/java/com/tencent/matrix/memory/canary/trim/TrimMemoryNotifier.kt:127

            if (nextIndex < config.delayMillis.size) {
                delayIndex = nextIndex
                val delay = config.delayMillis[nextIndex]
                runningHandler.postDelayed(this, delay)
                MatrixLog.i(
                    TAG,
                    "...[$name] trim delay[${nextIndex + 1}/${config.delayMillis.size}] $delay"
                )
            }
        }
    }

    fun init(config: TrimMemoryConfig) {
        if (!config.enable) {
            return
        }

        if (config.delayMillis.isEmpty()) {
            throw IllegalArgumentException("config.delayMillis is empty")
        }

        if (!Matrix.isInstalled()) {
            MatrixLog.e(TAG, "Matrix NOT installed yet")
            return
        }

        // system trim
        Matrix.with().application.registerComponentCallbacks(object : ComponentCallbacks2 {

            private var lastTrimTimeMillis = 0L

            @Volatile
            private var trimCounter = 0
            private val maxTrimCount = 10

            init {
                ProcessExplicitBackgroundOwner.addLifecycleCallback(object :

View on GitHub (pinned to 3b8293bd65)