{"record":{"id":"0b3d3b3151376ac9","repo":"DrKLO/Telegram","slug":"invalid-orientation-it-should-be-either-horizonta","errorCode":null,"errorMessage":"Invalid orientation. It should be either HORIZONTAL or VERTICAL","messagePattern":"Invalid orientation\\. It should be either HORIZONTAL or VERTICAL","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/androidx/recyclerview/widget/DividerItemDecoration.java","lineNumber":85,"sourceCode":"        final TypedArray a = context.obtainStyledAttributes(ATTRS);\n        mDivider = a.getDrawable(0);\n        if (mDivider == null) {\n            Log.w(TAG, \"@android:attr/listDivider was not set in the theme used for this \"\n                    + \"DividerItemDecoration. Please set that attribute all call setDrawable()\");\n        }\n        a.recycle();\n        setOrientation(orientation);\n    }\n\n    /**\n     * Sets the orientation for this divider. This should be called if\n     * {@link RecyclerView.LayoutManager} changes orientation.\n     *\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    /**","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/androidx/recyclerview/widget/DividerItemDecoration.java#L67-L103","documentation":"DividerItemDecoration draws a divider line/drawable between items and must know whether the list scrolls horizontally or vertically so it can position the drawable on the correct axis. setOrientation accepts only HORIZONTAL (0) or VERTICAL (1) from LinearLayoutManager. Any other int (e.g. -1, 2, or an unrelated constant) is meaningless for divider placement and is rejected immediately rather than silently rendering nothing.","triggerScenarios":"Passing layoutManager.canScrollVertically() ? 1 : 0 incorrectly; passing RecyclerView.HORIZONTAL/VERTICAL when out of sync with the actual LayoutManager orientation; passing a raw int from a config/JSON without validation; calling setOrientation with a value computed from a null LayoutManager.","commonSituations":"Hardcoding orientation then later switching the LayoutManager; reading orientation from a preferences file that can be corrupt; copy-pasting a DividerItemDecoration setup that referenced a different constant set.","solutions":["Derive orientation from the LayoutManager: dividerItemDecoration.setOrientation(((LinearLayoutManager) layoutManager).getOrientation());","After calling layoutManager.setOrientation(...), also update the divider.","Validate the int is 0 or 1 before calling setOrientation if it comes from external input."],"exampleFix":"// before\nDividerItemDecoration did = new DividerItemDecoration(this, 5); // throws\n\n// after\nint orientation = ((LinearLayoutManager) layoutManager).getOrientation();\nDividerItemDecoration did = new DividerItemDecoration(this, orientation);","handlingStrategy":"validation","validationCode":"// Derive orientation from the actual LayoutManager\nint safeOrientation(RecyclerView.LayoutManager lm) {\n    if (!(lm instanceof LinearLayoutManager)) return DividerItemDecoration.VERTICAL;\n    return ((LinearLayoutManager) lm).getOrientation();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always read orientation from the LinearLayoutManager rather than hardcoding.","When switching LayoutManager orientation, update the divider too.","Validate externally-sourced orientation ints against {0,1}."],"tags":["recyclerview","divider","orientation","configuration"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}