Tencent/matrix · error · IllegalStateException
Supervisor NOT initialized yet or Supervisor is disabled!!!
Error message
Supervisor NOT initialized yet or Supervisor is disabled!!!
What it means
ProcessSupervisor.isSupervisor lazily determines this process's role by inspecting declared services, which requires that ProcessSupervisor.init(application) stored a non-null application. If application is null (init never ran, or the supervisor is disabled/not installed), the lazy property throws IllegalStateException instead of returning a role.
Solutions
- Call ProcessSupervisor.init(application) in Application.onCreate before any code reads isSupervisor.
- Ensure the supervisor is enabled in Matrix config so init stores the application reference.
- Wrap reads in a check like `if (Matrix.isInstalled())` and defer role-dependent logic until install completes.
- Catch IllegalStateException around first access of isSupervisor when init timing cannot be guaranteed.
Example fix
// before val isSupervisor = ProcessSupervisor.isSupervisor // after ProcessSupervisor.init(application) // in Application.onCreate val isSupervisor = ProcessSupervisor.isSupervisor
Defensive patterns
Strategy: validation
Validate before calling
if (!Matrix.isInstalled()) {
throw IllegalStateException("Call ProcessSupervisor.init(application) first")
}
val isSupervisor = ProcessSupervisor.isSupervisor Type guard
fun supervisorRoleOrNull(): Boolean? =
if (Matrix.isInstalled()) ProcessSupervisor.isSupervisor else null Try / catch
val isSupervisor = try {
ProcessSupervisor.isSupervisor
} catch (e: IllegalStateException) {
MatrixLog.w(TAG, "supervisor not initialized", e)
false
} Prevention
- Always call ProcessSupervisor.init(application) in Application.onCreate.
- Do not read isSupervisor from initializers that run before Application.onCreate.
- Keep the supervisor enable flag consistent between config and call sites.
When it happens
Trigger: Reading ProcessSupervisor.isSupervisor (directly or transitively, e.g. isAppDeepBackground, dispatcher/subordinate accessors) before ProcessSupervisor.init(application) has run, or when the supervisor plugin is disabled via config.
Common situations: Accessing supervisor properties in a library's own initializer that runs before Application.onCreate init; Matrix install skipped in this process; enabling/disabling supervisor via config without updating call sites.
Related errors
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/c8ba3538830e0602.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/ProcessSupervisor.kt:109
@Volatile
private var application: Application? = null
internal var config: SupervisorConfig? = null
val isAppUIForeground: Boolean
get() = appUIForegroundOwner.active()
val isAppExplicitBackground: Boolean
get() = appExplicitBackgroundOwner.active()
val isAppStagedBackground: Boolean
get() = appStagedBackgroundOwner.active()
val isAppDeepBackground: Boolean
get() = appDeepBackgroundOwner.active()
val isSupervisor: Boolean by lazy {
if (application == null) {
throw IllegalStateException("Supervisor NOT initialized yet or Supervisor is disabled!!!")
}
val serviceInfo = safeLetOrNull(TAG) {
application!!.packageManager.getPackageInfo(
application!!.packageName, PackageManager.GET_SERVICES
).services.find {
it.name == SupervisorService::class.java.name
}
}
// serviceInfo might be null
return@lazy MatrixUtil.getProcessName(application!!) == serviceInfo?.processName || SupervisorService.isSupervisor
}
@Volatile
internal var supervisorProxy: ISupervisorProxy? = null
internal const val STARTED_STATE_OWNER = "StartedStateOwner"View on GitHub (pinned to 3b8293bd65)