{"record":{"id":"a4cb04cea22091a1","repo":"Tencent/matrix","slug":"max-check-times-should-be-greater-than-0","errorCode":null,"errorMessage":"max check times should be greater than 0","messagePattern":"max check times should be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessBackgroundStateOwner.kt","lineNumber":149,"sourceCode":" *\n * notice: same as [ProcessExplicitBackgroundOwner]\n */\nobject ProcessStagedBackgroundOwner : StatefulOwner(), IBackgroundStatefulOwner {\n    private const val TAG = \"Matrix.background.Staged\"\n\n    var maxCheckInterval = MAX_CHECK_INTERVAL\n        set(value) {\n            if (value < TimeUnit.SECONDS.toMillis(10)) {\n                throw IllegalArgumentException(\"interval should NOT be less than 10s\")\n            }\n            field = value\n            MatrixLog.i(TAG, \"set max check interval as $value\")\n        }\n\n    var maxCheckTimes = MAX_CHECK_TIMES\n        set(value) {\n            if (value <= 0) {\n                throw IllegalArgumentException(\"max check times should be greater than 0\")\n            }\n            field = value\n            MatrixLog.i(TAG, \"set max check interval as $value\")\n        }\n\n    private val checkTask = object : TimerChecker(TAG, maxCheckInterval, maxCheckTimes) {\n        override fun action(): Boolean {\n            if (ProcessExplicitBackgroundOwner.active()\n                && (ProcessUILifecycleOwner.hasRunningAppTask()\n                    .also { MatrixLog.i(TAG, \"hasRunningAppTask? $it\") }\n                        || ProcessUICreatedStateOwner.active())\n            ) {\n                MatrixLog.i(TAG, \"turn ON\")\n                turnOn() // staged background\n                return true\n            }\n            MatrixLog.i(TAG, \"turn off\")\n            turnOff() // means deep background","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessBackgroundStateOwner.kt#L131-L167","documentation":"ProcessStagedBackgroundOwner.maxCheckTimes limits how many interval checks run before declaring the process backgrounded. It must be at least 1; setting a value <= 0 throws IllegalArgumentException because a zero/negative count makes the staged check never complete.","triggerScenarios":"Assigning ProcessStagedBackgroundOwner.maxCheckTimes = 0 or a negative number while configuring the staged background detection.","commonSituations":"Disabling staged checks by setting 0 (not supported); computing the count dynamically (e.g. totalWindow / interval) and producing 0 when the interval is large.","solutions":["Set maxCheckTimes to at least 1.","Guard computed values: coerceAtLeast(1) before assigning.","If you want to disable staged checking, don't use ProcessStagedBackgroundOwner; use ProcessExplicitBackgroundOwner instead."],"exampleFix":"// before\nProcessStagedBackgroundOwner.maxCheckTimes = 0 // throws\n// after\nProcessStagedBackgroundOwner.maxCheckTimes = computedTimes.coerceAtLeast(1)","handlingStrategy":"validation","validationCode":"fun setStagedTimes(times: Int) {\n    require(times > 0) { \"maxCheckTimes must be > 0\" }\n    ProcessStagedBackgroundOwner.maxCheckTimes = times\n}","typeGuard":"null","tryCatchPattern":"try {\n    ProcessStagedBackgroundOwner.maxCheckTimes = configuredTimes\n} catch (e: IllegalArgumentException) {\n    MatrixLog.w(TAG, \"times must be > 0, using default\")\n}","preventionTips":["coerceAtLeast(1) any dynamically computed check count.","Don't use 0 to 'disable' staged checks; switch owners instead.","Validate config values at load time, before assignment."],"tags":["android","config","argument-out-of-range"],"backgroundTag":"invalid-config-value","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"}