{"record":{"id":"8846be3de982f04f","repo":"Tencent/matrix","slug":"jobconfig-can-not-be-null","errorCode":null,"errorMessage":"---jobConfig can not be null!","messagePattern":"---jobConfig can not be null!","errorType":"exception","errorClass":"TaskInitException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/ApkTask.java","lineNumber":60,"sourceCode":"\n    public interface ApkTaskProgressListener {\n        void getProgress(int progress, String message);\n    }\n\n\n    public ApkTask(JobConfig config, Map<String, String> params) {\n        this.params = params;\n        this.config = config;\n        progressListeners = new LinkedList<>();\n    }\n\n    public int getType() {\n        return type;\n    }\n\n    public void init() throws TaskInitException {\n        if (config == null) {\n            throw new TaskInitException(TAG + \"---jobConfig can not be null!\");\n        }\n\n        if (params == null) {\n            throw new TaskInitException(TAG + \"---params can not be null!\");\n        }\n    }\n\n    public void addProgressListener(ApkTaskProgressListener listener) {\n        if (listener != null) {\n            progressListeners.add(listener);\n        }\n    }\n\n    public void removeProgressListener(ApkTaskProgressListener listener) {\n        if (listener != null) {\n            progressListeners.remove(listener);\n        }\n    }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/ApkTask.java#L42-L78","documentation":"ApkTask is the base class for APK canary checker tasks. init() validates that the task has been given a JobConfig before running; if the config field is null it throws TaskInitException with this message. This is a fail-fast guard so tasks never execute unconfigured.","triggerScenarios":"Registering/executing an ApkTask subclass without calling its setter (or constructor path) that supplies the JobConfig — i.e. the task executor ran init() on a task whose config was never assigned.","commonSituations":"Custom ApkTask implementations that override how config is injected and forget to set it; programmatically constructing a task and calling execute()/init() directly without calling the config setter; framework wiring changes that drop config propagation.","solutions":["Call the task's config setter (setConfig / constructor parameter) with a valid non-null JobConfig before invoking init().","If writing a custom task, ensure the base class field is populated by your injection code rather than shadowing it.","Check the task-creation/factory code so every task added to the job receives the shared JobConfig.","Add an assertion or unit test asserting task.getConfig() != null before job execution."],"exampleFix":"// before\nApkTask task = new CountClassTask();\ntask.init();\n// after\nApkTask task = new CountClassTask();\ntask.setConfig(jobConfig);\ntask.setParams(params);\ntask.init();","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(task, \"task\");\nif (task.getConfig() == null) {\n    throw new IllegalStateException(\"JobConfig missing for task before init()\");\n}","typeGuard":"boolean isConfigured(ApkTask task) {\n    return task != null && task.getConfig() != null;\n}","tryCatchPattern":"try {\n    task.init();\n} catch (TaskInitException e) {\n    MatrixLog.e(TAG, \"task init failed: %s\", e.getMessage());\n    throw e; // config errors should fail the job fast\n}","preventionTips":["Always pair task creation with setConfig(...) in your factory/runner code.","Write a unit test that initializes every registered ApkTask with a real JobConfig.","Make config a constructor parameter in custom tasks.","Fail the job at assembly time if any task lacks a config."],"tags":["apk-canary","task-init","missing-config","validation"],"backgroundTag":"missing-required-config","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"}