{"record":{"id":"77bbd8de13ff067e","repo":"DrKLO/Telegram","slug":"drawable-cannot-be-null","errorCode":null,"errorMessage":"Drawable cannot be null.","messagePattern":"Drawable cannot be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/androidx/recyclerview/widget/DividerItemDecoration.java","lineNumber":98,"sourceCode":"     *\n     * @param orientation {@link #HORIZONTAL} or {@link #VERTICAL}\n     */\n    public void setOrientation(int orientation) {\n        if (orientation != HORIZONTAL && orientation != VERTICAL) {\n            throw new IllegalArgumentException(\n                    \"Invalid orientation. It should be either HORIZONTAL or VERTICAL\");\n        }\n        mOrientation = orientation;\n    }\n\n    /**\n     * Sets the {@link Drawable} for this divider.\n     *\n     * @param drawable Drawable that should be used as a divider.\n     */\n    public void setDrawable(@NonNull Drawable drawable) {\n        if (drawable == null) {\n            throw new IllegalArgumentException(\"Drawable cannot be null.\");\n        }\n        mDivider = drawable;\n    }\n\n    /**\n     * @return the {@link Drawable} for this divider.\n     */\n    @Nullable\n    public Drawable getDrawable() {\n        return mDivider;\n    }\n\n    @Override\n    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {\n        if (parent.getLayoutManager() == null || mDivider == null) {\n            return;\n        }\n        if (mOrientation == VERTICAL) {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/androidx/recyclerview/widget/DividerItemDecoration.java#L80-L116","documentation":"DividerItemDecoration requires a non-null Drawable to draw the divider line; a null mDivider would cause an NPE deep in Canvas.draw during onDraw. setDrawable is annotated @NonNull and checks the argument defensively so the failure is reported at configuration time with a clear message rather than as an opaque NPE during draw. The most common cause is passing getResources().getDrawable(id) which returns null on certain configurations or before resources are ready, or passing a drawable that failed to load.","triggerScenarios":"Passing ContextCompat.getDrawable(context, resId) when resId is 0/invalid; passing a Drawable loaded from a stream that returned null; calling setDrawable(null) intentionally to 'clear' the divider (the API does not support null).","commonSituations":"Reading a divider resource id from a theme/attr that resolves to 0; using getDrawable on a resource missing from some density buckets; a runtime resource overlay that removed the drawable.","solutions":["Resolve the Drawable before passing it and null-check the result.","If you need no divider, remove the DividerItemDecoration from the RecyclerView instead of setting a null drawable.","Use AppCompatResources.getDrawable(context, R.drawable.x) which never returns null for valid resources (throws otherwise, surfacing the real problem)."],"exampleFix":"// before\ndid.setDrawable(getDrawable(R.drawable.missing)); // may be null\n\n// after\nDrawable d = AppCompatResources.getDrawable(this, R.drawable.divider);\nif (d != null) {\n    did.setDrawable(d);\n} else {\n    recyclerView.removeItemDecoration(did);\n}","handlingStrategy":"type-guard","validationCode":"// Resolve drawable and guard against null\nDrawable d = AppCompatResources.getDrawable(context, resId);\nif (d != null) {\n    dividerItemDecoration.setDrawable(d);\n} else {\n    recyclerView.removeItemDecoration(dividerItemDecoration);\n}","typeGuard":"// Java: null-check at the boundary\nboolean isValidDrawable(Drawable d) { return d != null; }","tryCatchPattern":null,"preventionTips":["Use AppCompatResources.getDrawable which never returns null for valid ids.","To clear a divider, remove the ItemDecoration rather than passing null.","Validate resource ids from themes/attrs are non-zero before resolving."],"tags":["recyclerview","divider","drawable","null-check","resources"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}