{"record":{"id":"fc37ed85dc271244","repo":"Tencent/matrix","slug":"work-must-not-be-null","errorCode":null,"errorMessage":"work must not be null","messagePattern":"work must not be null","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":533,"sourceCode":"                                   @NonNull Intent work) {\n        enqueueWork(context, new ComponentName(context, cls), jobId, work);\n    }\n\n    /**\n     * Like {@link #enqueueWork(Context, Class, int, Intent)}, but supplies a ComponentName\n     * for the service to interact with instead of its class.\n     *\n     * @param context Context this is being called from.\n     * @param component The published ComponentName of the class this work should be\n     * dispatched to.\n     * @param jobId A unique job ID for scheduling; must be the same value for all work\n     * enqueued for the same class.\n     * @param work The Intent of work to enqueue.\n     */\n    public static void enqueueWork(@NonNull Context context, @NonNull ComponentName component,\n                                   int jobId, @NonNull Intent work) {\n        if (work == null) {\n            throw new IllegalArgumentException(\"work must not be null\");\n        }\n        synchronized (sLock) {\n            WorkEnqueuer we = getWorkEnqueuer(context, component, true, jobId);\n            we.ensureJobId(jobId);\n            we.enqueueWork(work);\n        }\n    }\n\n    static WorkEnqueuer getWorkEnqueuer(Context context, ComponentName cn, boolean hasJobId,\n                                        int jobId) {\n        WorkEnqueuer we = sClassWorkEnqueuer.get(cn);\n        if (we == null) {\n            if (Build.VERSION.SDK_INT >= 26) {\n                if (!hasJobId) {\n                    throw new IllegalArgumentException(\"Can't be here without a job id\");\n                }\n                we = new JobWorkEnqueuer(context, cn, jobId);\n            } else {","sourceCodeStart":515,"sourceCodeEnd":551,"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#L515-L551","documentation":"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.","triggerScenarios":"Calling MatrixJobIntentService.enqueueWork(context, component, jobId, null) — i.e. passing a null Intent as the `work` parameter.","commonSituations":"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.","solutions":["Ensure the Intent passed to enqueueWork is non-null: construct it explicitly with new Intent(context, ComponentName) or similar before calling.","Add a null check at the call site and skip/short-circuit the enqueue when the Intent cannot be built.","If the Intent comes from an external source, log and drop null values instead of forwarding them."],"exampleFix":"// before\nIntent work = buildWorkIntent(); // may return null\nMatrixJobIntentService.enqueueWork(context, component, jobId, work);\n// after\nIntent work = buildWorkIntent();\nif (work != null) {\n    MatrixJobIntentService.enqueueWork(context, component, jobId, work);\n}","handlingStrategy":"validation","validationCode":"if (work == null) {\n    Log.w(TAG, \"skip enqueueWork: null intent\");\n    return;\n}\nMatrixJobIntentService.enqueueWork(context, component, jobId, work);","typeGuard":"if (work instanceof Intent) { MatrixJobIntentService.enqueueWork(context, component, jobId, work); }","tryCatchPattern":"try {\n    MatrixJobIntentService.enqueueWork(context, component, jobId, work);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"enqueueWork rejected\", e);\n}","preventionTips":["Never pass a nullable Intent result directly into enqueueWork; build it at the call site.","Centralize enqueueWork calls in one helper that null-checks first.","Add unit tests covering the intent-building path returning null."],"tags":["android","null-argument","illegal-argument"],"backgroundTag":"null-argument","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"}