Tencent/matrix · error · IllegalArgumentException

work must not be null

Error message

work must not be null

What it means

MatrixJobIntentService.enqueueWork() is a static helper (mirroring androidx JobIntentService) that schedules an Intent of work for processing. It explicitly validates the `work` Intent argument before enqueueing, and throws IllegalArgumentException when it is null. The library treats a null Intent as a programming error that would otherwise crash later inside the job scheduler.

Solutions

  1. Ensure the Intent passed to enqueueWork is non-null: construct it explicitly with new Intent(context, ComponentName) or similar before calling.
  2. Add a null check at the call site and skip/short-circuit the enqueue when the Intent cannot be built.
  3. If the Intent comes from an external source, log and drop null values instead of forwarding them.

Example fix

// before
Intent work = buildWorkIntent(); // may return null
MatrixJobIntentService.enqueueWork(context, component, jobId, work);
// after
Intent work = buildWorkIntent();
if (work != null) {
    MatrixJobIntentService.enqueueWork(context, component, jobId, work);
}
Defensive patterns

Strategy: validation

Validate before calling

if (work == null) {
    Log.w(TAG, "skip enqueueWork: null intent");
    return;
}
MatrixJobIntentService.enqueueWork(context, component, jobId, work);

Type guard

if (work instanceof Intent) { MatrixJobIntentService.enqueueWork(context, component, jobId, work); }

Try / catch

try {
    MatrixJobIntentService.enqueueWork(context, component, jobId, work);
} catch (IllegalArgumentException e) {
    Log.e(TAG, "enqueueWork rejected", e);
}

Prevention

When it happens

Trigger: Calling MatrixJobIntentService.enqueueWork(context, component, jobId, null) — i.e. passing a null Intent as the `work` parameter.

Common situations: An upstream method returns an Intent that can be null (e.g. parsing a notification/push payload fails) and its result is passed straight to enqueueWork without a null check; refactorings where the Intent construction is conditionally skipped.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/fc37ed85dc271244. 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:533

                                   @NonNull Intent work) {
        enqueueWork(context, new ComponentName(context, cls), jobId, work);
    }

    /**
     * Like {@link #enqueueWork(Context, Class, int, Intent)}, but supplies a ComponentName
     * for the service to interact with instead of its class.
     *
     * @param context Context this is being called from.
     * @param component The published ComponentName of the class this work should be
     * dispatched to.
     * @param jobId A unique job ID for scheduling; must be the same value for all work
     * enqueued for the same class.
     * @param work The Intent of work to enqueue.
     */
    public static void enqueueWork(@NonNull Context context, @NonNull ComponentName component,
                                   int jobId, @NonNull Intent work) {
        if (work == null) {
            throw new IllegalArgumentException("work must not be null");
        }
        synchronized (sLock) {
            WorkEnqueuer we = getWorkEnqueuer(context, component, true, jobId);
            we.ensureJobId(jobId);
            we.enqueueWork(work);
        }
    }

    static WorkEnqueuer getWorkEnqueuer(Context context, ComponentName cn, boolean hasJobId,
                                        int jobId) {
        WorkEnqueuer we = sClassWorkEnqueuer.get(cn);
        if (we == null) {
            if (Build.VERSION.SDK_INT >= 26) {
                if (!hasJobId) {
                    throw new IllegalArgumentException("Can't be here without a job id");
                }
                we = new JobWorkEnqueuer(context, cn, jobId);
            } else {

View on GitHub (pinned to 3b8293bd65)