{"record":{"id":"d739f3ba37f58f92","repo":"Tencent/matrix","slug":"not-initialized-yet-d739f3","errorCode":null,"errorMessage":"not initialized yet !","messagePattern":"not initialized yet !","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/SupervisorService.kt","lineNumber":289,"sourceCode":"    override fun onDestroy() {\n        super.onDestroy()\n        MatrixLog.e(TAG, \"SupervisorService destroyed!!!\")\n        instance = null\n    }\n\n    internal fun backgroundLruKill(\n        killedCallback: (result: Int, process: String?, pid: Int) -> Unit\n    ) {\n        if (true != ProcessSupervisor.config?.enable) {\n            MatrixLog.e(TAG, \"supervisor was disabled\")\n            return\n        }\n        if (!isSupervisor) {\n            throw IllegalStateException(\"backgroundLruKill should only be called in supervisor\")\n        }\n\n        if (instance == null) {\n            throw IllegalStateException(\"not initialized yet !\")\n        }\n\n        targetKilledCallback = killedCallback\n        val candidate = backgroundProcessLru.firstOrNull {\n            it.name != MatrixUtil.getProcessName(this)\n                    && !ProcessSupervisor.config!!.lruKillerWhiteList.contains(it.name)\n        }\n\n        if (candidate != null) {\n//            DispatchReceiver.dispatchKill(this, candidate.name, candidate.pid)\n            ProcessSubordinate.manager.dispatchKill(recentScene, candidate.name, candidate.pid)\n        } else {\n            killedCallback.invoke(LRU_KILL_NOT_FOUND, null, -1)\n        }\n    }\n\n    private class TokenRecord {\n        private val pidToToken: ConcurrentHashMap<Int, ProcessToken>","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/SupervisorService.kt#L271-L307","documentation":"After passing the supervisor-role check, backgroundLruKill() also requires that the SupervisorService instance has been created (e.g. via startService/onCreate). It throws IllegalStateException(\"not initialized yet !\") when instance is null, meaning the service was never started in the supervisor process.","triggerScenarios":"Calling backgroundLruKill from the supervisor process before SupervisorService has been started/bound (startService(context) or equivalent init), or after the service was destroyed.","commonSituations":"Invoking LRU kill very early in app startup before the supervisor service starts; service killed by the system and not restarted while the caller still invokes the static method; forgetting to start the service in the supervisor process.","solutions":["Ensure SupervisorService is started in the supervisor process (context.startService) before calling backgroundLruKill.","Check instance availability (or catch the exception) and start the service lazily on first use.","Re-trigger service start on onServiceDisconnected/onTaskRemoved paths so it is always alive in the supervisor.","Defer LRU-kill calls until after Application init where the service has certainly started."],"exampleFix":"// before\nSupervisorService.backgroundLruKill(killedCallback)\n// after\ncontext.startService(Intent(context, SupervisorService::class.java))\nSupervisorService.backgroundLruKill(killedCallback)","handlingStrategy":"validation","validationCode":"if (ProcessSupervisor.isSupervisor) {\n    context.startService(Intent(context, SupervisorService::class.java))\n    SupervisorService.backgroundLruKill(killedCallback)\n}","typeGuard":"fun serviceReady(): Boolean = ProcessSupervisor.isSupervisor // ensure service started via startService beforehand","tryCatchPattern":"try {\n    SupervisorService.backgroundLruKill(killedCallback)\n} catch (e: IllegalStateException) {\n    MatrixLog.w(TAG, \"SupervisorService not started, starting now\", e)\n    context.startService(Intent(context, SupervisorService::class.java))\n}","preventionTips":["Start SupervisorService during supervisor-process startup before exposing kill APIs.","Restart the service on disconnect/system-kill callbacks.","Sequence LRU-kill calls after Application init completes."],"tags":["android","service-lifecycle","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"}