{"record":{"id":"4875e651128997c4","repo":"didi/DoKit","slug":"network-policy-cannot-be-null","errorCode":null,"errorMessage":"Network policy cannot be null.","messagePattern":"Network policy cannot be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":369,"sourceCode":"        }\n        if (additional.length > 0) {\n            for (MemoryPolicy memoryPolicy : additional) {\n                if (memoryPolicy == null) {\n                    throw new IllegalArgumentException(\"Memory policy cannot be null.\");\n                }\n                this.memoryPolicy |= memoryPolicy.index;\n            }\n        }\n        return this;\n    }\n\n    /**\n     * Specifies the {@link NetworkPolicy} to use for this request. You may specify additional policy\n     * options using the varargs parameter.\n     */\n    public RequestCreator networkPolicy(NetworkPolicy policy, NetworkPolicy... additional) {\n        if (policy == null) {\n            throw new IllegalArgumentException(\"Network policy cannot be null.\");\n        }\n        this.networkPolicy |= policy.index;\n        if (additional == null) {\n            throw new IllegalArgumentException(\"Network policy cannot be null.\");\n        }\n        if (additional.length > 0) {\n            for (NetworkPolicy networkPolicy : additional) {\n                if (networkPolicy == null) {\n                    throw new IllegalArgumentException(\"Network policy cannot be null.\");\n                }\n                this.networkPolicy |= networkPolicy.index;\n            }\n        }\n        return this;\n    }\n\n    /**\n     * Disable brief fade in of images loaded from the disk cache or network.","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L351-L387","documentation":"Thrown by RequestCreator.networkPolicy(MemoryPolicy's counterpart) networkPolicy(NetworkPolicy, NetworkPolicy...) when the required first policy argument is null. NetworkPolicy flags (NO_CACHE, NO_STORE, OFFLINE) control OkHttp cache behavior; a null primary policy is rejected immediately with IllegalArgumentException.","triggerScenarios":"Calling networkPolicy(null), or passing a nullable variable (e.g. an offline-mode flag resolved to null) as the first argument.","commonSituations":"Offline/online mode switches where the policy is computed conditionally and the online branch yields null; config-driven network policies decoded from JSON/preferences; refactoring from deprecated APIs where null slipped through.","solutions":["Pass a concrete NetworkPolicy, e.g. networkPolicy(OFFLINE) for offline mode","Guard nullable values: if (policy != null) rc.networkPolicy(policy);","Default the config field to a real policy so null never reaches the call"],"exampleFix":"// before\nNetworkPolicy p = isOffline() ? NetworkPolicy.OFFLINE : null;\npicasso.load(url).networkPolicy(p).into(imageView); // throws when null\n\n// after\nRequestCreator rc = picasso.load(url);\nif (isOffline()) rc.networkPolicy(NetworkPolicy.OFFLINE);\nrc.into(imageView);","handlingStrategy":"validation","validationCode":"if (networkPolicy != null) {\n    rc.networkPolicy(networkPolicy);\n}","typeGuard":"static NetworkPolicy requireNetworkPolicy(NetworkPolicy p) {\n    if (p == null) throw new IllegalArgumentException(\"NetworkPolicy required\");\n    return p;\n}","tryCatchPattern":null,"preventionTips":["Compute offline/online policy with concrete defaults, never null branches","Guard config-derived policy values before the call","Like memoryPolicy, the primary flag is applied before varargs validation — avoid reusing a half-configured builder"],"tags":["picasso","dokit","android","image-loading","network-policy","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}