{"record":{"id":"bad2bb5474706b05","repo":"Tencent/matrix","slug":"token-with-name-name-not-found","errorCode":null,"errorMessage":"token with name=$name not found","messagePattern":"token with name=\\$name not found","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":338,"sourceCode":"        fun removeToken(pid: Int): ProcessToken {\n            val rm = pidToToken.remove(pid)\n            rm?.let {\n                nameToToken.remove(rm.name)\n                return rm\n            }\n            throw IllegalStateException(\"token with pid=$pid not found\")\n        }\n\n        fun isEmpty(): Boolean =\n            pidToToken.isEmpty() || pidToToken.all { it.key == Process.myPid() }\n\n        fun removeToken(name: String): ProcessToken {\n            val rm = nameToToken.remove(name)\n            rm?.let {\n                pidToToken.remove(rm.pid)\n                return rm\n            }\n            throw IllegalStateException(\"token with name=$name not found\")\n        }\n    }\n\n    private class RemoteProcessLifecycleProxy(val token: ProcessToken) : StatefulOwner() {\n\n        init {\n            DispatcherStateOwner.addSourceOwner(\n                token.statefulName,\n                this\n            )\n        }\n\n        companion object {\n\n            private val processProxies by lazy { ConcurrentHashMap<ProcessToken, ConcurrentHashMap<String, RemoteProcessLifecycleProxy>>() }\n\n            fun getProxy(token: ProcessToken) =\n                processProxies.getOrPut(token, { ConcurrentHashMap() })","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/SupervisorService.kt#L320-L356","documentation":"The name-based overload removeToken(name) removes the ProcessToken registered for a process name. It throws IllegalStateException(\"token with name=$name not found\") when no such name is present in nameToToken — the process was never registered, or its token was already removed via the pid path.","triggerScenarios":"Calling removeToken(name) for a subordinate name that never registered, was already removed by removeToken(pid), or whose entry was purged on binder death before this call.","commonSituations":"Config-driven white/blacklist cleanup invoking removeToken for processes that never connected; double cleanup between pid-based and name-based paths; renamed processes after a build configuration change.","solutions":["Guard with a map lookup (or catch IllegalStateException) so removing an unknown name is a no-op.","Keep pid/name removal symmetric: removing by one key should not leave the other path expecting an entry.","Only call removeToken for names obtained from the supervisor's live token registry.","Log-and-skip unknown names in cleanup loops instead of letting the exception propagate."],"exampleFix":"// before\nval token = removeToken(name)\n// after\nval token = try {\n    removeToken(name)\n} catch (e: IllegalStateException) {\n    MatrixLog.w(TAG, \"token already removed for name=$name\")\n    null\n}","handlingStrategy":"fallback","validationCode":"if (name in supervisor.registeredNames) removeToken(name)","typeGuard":null,"tryCatchPattern":"val token = try {\n    removeToken(name)\n} catch (e: IllegalStateException) {\n    null // unknown or already-removed name — treat as no-op\n}","preventionTips":["Only remove names sourced from the live token registry.","Keep pid-based and name-based removal mutually exclusive per cleanup event.","Log unknown names during bulk cleanup instead of letting exceptions escape."],"tags":["android","process-supervisor","bookkeeping","state-race"],"backgroundTag":"record-not-found","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"}