{"record":{"id":"bb0c24b504d60ff5","repo":"Tencent/matrix","slug":"given-job-id","errorCode":null,"errorMessage":"Given job ID ","messagePattern":"Given job ID ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/MatrixJobIntentService.java","lineNumber":139,"sourceCode":"     * Base class for the target service we can deliver work to and the implementation of\n     * how to deliver that work.\n     */\n    abstract static class WorkEnqueuer {\n        final ComponentName mComponentName;\n\n        boolean mHasJobId;\n        int mJobId;\n\n        WorkEnqueuer(ComponentName cn) {\n            mComponentName = cn;\n        }\n\n        void ensureJobId(int jobId) {\n            if (!mHasJobId) {\n                mHasJobId = true;\n                mJobId = jobId;\n            } else if (mJobId != jobId) {\n                throw new IllegalArgumentException(\"Given job ID \" + jobId\n                        + \" is different than previous \" + mJobId);\n            }\n        }\n\n        abstract void enqueueWork(Intent work);\n\n        public void serviceStartReceived() {\n        }\n\n        public void serviceProcessingStarted() {\n        }\n\n        public void serviceProcessingFinished() {\n        }\n    }\n\n    /**\n     * Get rid of lint warnings about API levels.","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/MatrixJobIntentService.java#L121-L157","documentation":"MatrixJobIntentService's CompatJob.ensureJobId guarantees every work item enqueued into the same service uses one consistent job ID. If enqueueWork is called with a jobId that differs from one already recorded, it throws IllegalArgumentException to prevent mixing work under different job IDs.","triggerScenarios":"enqueueWork is called multiple times with different jobId values for the same CompatJob — e.g. enqueuing work from two components using distinct job IDs, or a hardcoded ID that was changed at one call site but not others.","commonSituations":"Copy-pasting sample code with a different JOB_ID constant while other call sites use the old one; multiple entry points sharing one MatrixJobIntentService; refactoring that renamed one job ID but not all.","solutions":["Use a single shared JOB_ID constant for all enqueueWork calls into the same service.","Grep the codebase for all enqueueWork call sites and unify their job IDs.","If distinct IDs are needed, use separate MatrixJobIntentService instances/work queues.","Validate that a configuration-provided job ID matches the existing one before enqueuing."],"exampleFix":"// before\nenqueueWork(context, MatrixJobIntentService.class, 100, work, true);\n// later elsewhere\nenqueueWork(context, MatrixJobIntentService.class, 200, work2, true); // throws\n// after\nprivate static final int JOB_ID = 100;\nenqueueWork(context, MatrixJobIntentService.class, JOB_ID, work, true);\nenqueueWork(context, MatrixJobIntentService.class, JOB_ID, work2, true);","handlingStrategy":"validation","validationCode":"static final int JOB_ID = 100;\n// assert before enqueue\nif (jobId != JOB_ID) throw new IllegalArgumentException(\"id mismatch\");","typeGuard":null,"tryCatchPattern":"try { enqueueWork(ctx, svc, jobId, work, true); } catch (IllegalArgumentException e) { log.error(\"job id mismatch: \" + e.getMessage()); }","preventionTips":["Define one JOB_ID constant shared by all call sites","Search for all enqueueWork usages during refactors","Use separate services if distinct job IDs are truly needed"],"tags":["android","background-work","jobintentservice","argument"],"backgroundTag":"invalid-argument-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"}