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
- Provide at least one value in delayMillis, e.g. longArrayOf(500, 1000, 3000).
- Or set enable=false so init returns early without validation.
- 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
- Validate dynamic/server config before passing it to init.
- Provide default delay values whenever enable=true.
- Add a unit test asserting init accepts only non-empty delay lists.
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
- Custom library loader is not supported in isolate process…
- LeakProcessor not found!!!
- Matrix is NOT installed or MemoryInfoFactory is not…
- Matrix init, Matrix should not be null.
- you must init Matrix sdk first
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)