{"record":{"id":"c14735d644f43d81","repo":"Blankj/AndroidUtilCode","slug":"invalid-orientation-it-should-be-either-horizonta-c14735","errorCode":null,"errorMessage":"Invalid orientation. It should be either HORIZONTAL or VERTICAL","messagePattern":"Invalid orientation\\. It should be either HORIZONTAL or VERTICAL","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/utildebug/src/main/java/com/blankj/utildebug/base/rv/RecycleViewDivider.java","lineNumber":57,"sourceCode":"    }\n\n    public RecycleViewDivider(Context context, int orientation, @NonNull Drawable divider) {\n        this(context, orientation, divider, false);\n    }\n\n    public RecycleViewDivider(Context context, int orientation, @DrawableRes int resId, boolean showFooterDivider) {\n        this(context, orientation, ContextCompat.getDrawable(context, resId), showFooterDivider);\n    }\n\n    public RecycleViewDivider(Context context, int orientation, @NonNull Drawable divider, boolean showFooterDivider) {\n        setOrientation(orientation);\n        mDivider = divider;\n        mShowFooterDivider = showFooterDivider;\n    }\n\n    private 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    @Override\n    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {\n        if (parent.getLayoutManager() == null) {\n            return;\n        }\n        if (mOrientation == VERTICAL) {\n            drawVertical(c, parent);\n        } else {\n            drawHorizontal(c, parent);\n        }\n    }\n\n    @SuppressLint(\"NewApi\")","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utildebug/src/main/java/com/blankj/utildebug/base/rv/RecycleViewDivider.java#L39-L75","documentation":"RecycleViewDivider.setOrientation validates that orientation is exactly HORIZONTAL or VERTICAL (the class's own constants), throwing IllegalArgumentException otherwise. ItemDecoration divider drawing is axis-specific (drawVertical/drawHorizontal), so an unknown orientation would silently draw nothing or misdraw. The guard converts that silent failure into a loud contract violation at construction.","triggerScenarios":"Constructing new RecycleViewDivider(context, orientation, resId, showFooter) where orientation is neither HORIZONTAL nor VERTICAL — e.g. passing LinearLayoutManager.HORIZONTAL but from a different constant set, or a raw int like 2/3, or a layout manager's default.","commonSituations":"Passing RecyclerView.HORIZONTAL/VERTICAL instead of RecycleViewDivider's own constants when their values differ; passing a computed orientation that can be a third value; refactoring the constant values so callers pass stale numbers; copy-paste from a different divider API.","solutions":["Pass one of RecycleViewDivider.HORIZONTAL or RecycleViewDivider.VERTICAL explicitly.","If the orientation comes from a LayoutManager, map it to the divider's own constants before constructing.","Assert at the call site that orientation is one of the two allowed values.","Verify the constant values align (or keep them documented) so callers do not pass equivalent-but-wrong integers."],"exampleFix":"// before\nnew RecycleViewDivider(ctx, 2, R.drawable.divider, true); // throws\n\n// after\nnew RecycleViewDivider(ctx, RecycleViewDivider.VERTICAL, R.drawable.divider, true);","handlingStrategy":"validation","validationCode":"if (orientation != RecycleViewDivider.HORIZONTAL && orientation != RecycleViewDivider.VERTICAL) {\n  throw new IllegalArgumentException(\"orientation must be HORIZONTAL or VERTICAL\");\n}\nnew RecycleViewDivider(ctx, orientation, resId, showFooter);","typeGuard":null,"tryCatchPattern":"try {\n  new RecycleViewDivider(ctx, orientation, resId, showFooter);\n} catch (IllegalArgumentException e) {\n  orientation = (orientation != RecycleViewDivider.HORIZONTAL)\n      ? RecycleViewDivider.VERTICAL : RecycleViewDivider.HORIZONTAL;\n  new RecycleViewDivider(ctx, orientation, resId, showFooter);\n}","preventionTips":["Always pass RecycleViewDivider.HORIZONTAL/VERTICAL constants.","Map LayoutManager orientation to the divider's own constants before constructing.","Add a constant-value check if integrating with third-party orientation enums.","Unit-test both orientations in the divider."],"tags":["android","recyclerview","divider","validation","argument"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}