{"record":{"id":"a29959f96c817bc1","repo":"didi/DoKit","slug":"image-resource-id-may-not-be-0","errorCode":null,"errorMessage":"Image resource ID may not be 0.","messagePattern":"Image resource ID may not be 0\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":279,"sourceCode":"     * This will clear an image resource ID if one is set.\n     */\n    public Builder setUri(Uri uri) {\n      if (uri == null) {\n        throw new IllegalArgumentException(\"Image URI may not be null.\");\n      }\n      this.uri = uri;\n      this.resourceId = 0;\n      return this;\n    }\n\n    /**\n     * Set the target image resource ID.\n     * <p>\n     * This will clear an image Uri if one is set.\n     */\n    public Builder setResourceId(int resourceId) {\n      if (resourceId == 0) {\n        throw new IllegalArgumentException(\"Image resource ID may not be 0.\");\n      }\n      this.resourceId = resourceId;\n      this.uri = null;\n      return this;\n    }\n\n    /**\n     * Set the stable key to be used instead of the URI or resource ID when caching.\n     * Two requests with the same value are considered to be for the same resource.\n     */\n    public Builder stableKey(String stableKey) {\n      this.stableKey = stableKey;\n      return this;\n    }\n\n    /**\n     * Resize the image to the specified size in pixels.\n     * Use 0 as desired dimension to resize keeping aspect ratio.","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L261-L297","documentation":"Request.Builder.setResourceId() throws IllegalArgumentException when resourceId is 0. Resource ID 0 in Android means 'no resource', so a Request pointing at resource 0 is invalid; setting a URI (which clears resourceId to 0) is the supported way to express 'no resource'. Fail-fast guard.","triggerScenarios":"Calling setResourceId(0), e.g. passing an unresolvable or unresolved resource identifier such as 0 returned from Resources.getIdentifier() when the name was not found, or a default field value.","commonSituations":"Dynamically resolving icons by name with getIdentifier() which returns 0 on miss; server-driven resource names that do not exist in the app; passing a default int field that was never set.","solutions":["Resolve the resource first and fall back to a known-good drawable when getIdentifier() returns 0","Validate server/remote resource names against a local map of valid IDs before building the request","Use setUri(Uri) when the image is not a local resource"],"exampleFix":"// before\nint id = resources.getIdentifier(name, \"drawable\", pkg); // 0 when name missing\nrequestBuilder.setResourceId(id); // IllegalArgumentException\n\n// after\nint id = resources.getIdentifier(name, \"drawable\", pkg);\nif (id == 0) id = R.drawable.fallback;\nrequestBuilder.setResourceId(id);","handlingStrategy":"validation","validationCode":"int id = resources.getIdentifier(name, \"drawable\", packageName);\nif (id == 0) { id = R.drawable.image_fallback; } // or use setUri(remoteUrl)\nrequestBuilder.setResourceId(id);","typeGuard":"boolean isValidResourceId(int id) { return id != 0; }","tryCatchPattern":null,"preventionTips":["Never pass raw getIdentifier() results to setResourceId; check for 0 first","Map server-driven names to a compile-time resource map so misses are impossible"],"tags":["android","picasso","request","validation","resources"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}