Tencent/matrix · error · IllegalArgumentException

Given job ID

Error message

Given job ID 

What it means

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.

Solutions

  1. Use a single shared JOB_ID constant for all enqueueWork calls into the same service.
  2. Grep the codebase for all enqueueWork call sites and unify their job IDs.
  3. If distinct IDs are needed, use separate MatrixJobIntentService instances/work queues.
  4. Validate that a configuration-provided job ID matches the existing one before enqueuing.

Example fix

// before
enqueueWork(context, MatrixJobIntentService.class, 100, work, true);
// later elsewhere
enqueueWork(context, MatrixJobIntentService.class, 200, work2, true); // throws
// after
private static final int JOB_ID = 100;
enqueueWork(context, MatrixJobIntentService.class, JOB_ID, work, true);
enqueueWork(context, MatrixJobIntentService.class, JOB_ID, work2, true);
Defensive patterns

Strategy: validation

Validate before calling

static final int JOB_ID = 100;
// assert before enqueue
if (jobId != JOB_ID) throw new IllegalArgumentException("id mismatch");

Try / catch

try { enqueueWork(ctx, svc, jobId, work, true); } catch (IllegalArgumentException e) { log.error("job id mismatch: " + e.getMessage()); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/bb0c24b504d60ff5. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/MatrixJobIntentService.java:139

     * Base class for the target service we can deliver work to and the implementation of
     * how to deliver that work.
     */
    abstract static class WorkEnqueuer {
        final ComponentName mComponentName;

        boolean mHasJobId;
        int mJobId;

        WorkEnqueuer(ComponentName cn) {
            mComponentName = cn;
        }

        void ensureJobId(int jobId) {
            if (!mHasJobId) {
                mHasJobId = true;
                mJobId = jobId;
            } else if (mJobId != jobId) {
                throw new IllegalArgumentException("Given job ID " + jobId
                        + " is different than previous " + mJobId);
            }
        }

        abstract void enqueueWork(Intent work);

        public void serviceStartReceived() {
        }

        public void serviceProcessingStarted() {
        }

        public void serviceProcessingFinished() {
        }
    }

    /**
     * Get rid of lint warnings about API levels.

View on GitHub (pinned to 3b8293bd65)