{"record":{"id":"c8ba3538830e0602","repo":"Tencent/matrix","slug":"supervisor-not-initialized-yet-or-supervisor-is-di","errorCode":null,"errorMessage":"Supervisor NOT initialized yet or Supervisor is disabled!!!","messagePattern":"Supervisor NOT initialized yet or Supervisor is disabled!!!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/ProcessSupervisor.kt","lineNumber":109,"sourceCode":"    @Volatile\n    private var application: Application? = null\n    internal var config: SupervisorConfig? = null\n\n    val isAppUIForeground: Boolean\n        get() = appUIForegroundOwner.active()\n\n    val isAppExplicitBackground: Boolean\n        get() = appExplicitBackgroundOwner.active()\n\n    val isAppStagedBackground: Boolean\n        get() = appStagedBackgroundOwner.active()\n\n    val isAppDeepBackground: Boolean\n        get() = appDeepBackgroundOwner.active()\n\n    val isSupervisor: Boolean by lazy {\n        if (application == null) {\n            throw IllegalStateException(\"Supervisor NOT initialized yet or Supervisor is disabled!!!\")\n        }\n\n        val serviceInfo = safeLetOrNull(TAG) {\n            application!!.packageManager.getPackageInfo(\n                application!!.packageName, PackageManager.GET_SERVICES\n            ).services.find {\n                it.name == SupervisorService::class.java.name\n            }\n        }\n\n        // serviceInfo might be null\n        return@lazy MatrixUtil.getProcessName(application!!) == serviceInfo?.processName || SupervisorService.isSupervisor\n    }\n\n    @Volatile\n    internal var supervisorProxy: ISupervisorProxy? = null\n\n    internal const val STARTED_STATE_OWNER = \"StartedStateOwner\"","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/ProcessSupervisor.kt#L91-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nval isSupervisor = ProcessSupervisor.isSupervisor\n// after\nProcessSupervisor.init(application) // in Application.onCreate\nval isSupervisor = ProcessSupervisor.isSupervisor","handlingStrategy":"validation","validationCode":"if (!Matrix.isInstalled()) {\n    throw IllegalStateException(\"Call ProcessSupervisor.init(application) first\")\n}\nval isSupervisor = ProcessSupervisor.isSupervisor","typeGuard":"fun supervisorRoleOrNull(): Boolean? =\n    if (Matrix.isInstalled()) ProcessSupervisor.isSupervisor else null","tryCatchPattern":"val isSupervisor = try {\n    ProcessSupervisor.isSupervisor\n} catch (e: IllegalStateException) {\n    MatrixLog.w(TAG, \"supervisor not initialized\", e)\n    false\n}","preventionTips":["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."],"tags":["android","process-supervisor","initialization-order","illegal-state"],"backgroundTag":"module-init-failed","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"}