{"record":{"id":"b9fdfefcdcdcdba8","repo":"Blankj/AndroidUtilCode","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":"lib/base/src/main/java/com/blankj/base/rv/RecycleViewDivider.java","lineNumber":56,"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":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/base/src/main/java/com/blankj/base/rv/RecycleViewDivider.java#L38-L74","documentation":"RecycleViewDivider.setOrientation throws IllegalArgumentException unless the orientation is exactly HORIZONTAL (LinearLayout.HORIZONTAL==0) or VERTICAL (LinearLayout.VERTICAL==1). The divider must know its drawing axis, so any other int is rejected at construction.","triggerScenarios":"Passing an arbitrary int, a wrong constant, or a recycled/initialised-to-default (-1 or 0 interpreted wrong) value as the orientation argument to any RecycleViewDivider constructor.","commonSituations":"Passing RecyclerView.HORIZONTAL/VERTICAL by mistake instead of RecycleViewDivider.HORIZONTAL/VERTICAL (values happen to match but reads wrong); passing a LayoutManager orientation constant stored in a variable that defaulted to 0/other; passing a configuration value read from resources as a raw int.","solutions":["Pass one of the RecycleViewDivider.HORIZONTAL or RecycleViewDivider.VERTICAL constants explicitly.","If the orientation comes from a variable, validate it is 0 or 1 (or one of the two constants) before constructing the divider.","Use the matching constant names (RecycleViewDivider.HORIZONTAL/VERTICAL) to avoid confusing them with other libraries' constants."],"exampleFix":"// before\nnew RecycleViewDivider(ctx, layoutManager.getOrientation(), R.drawable.div);\n// if getOrientation returns an unexpected value -> throws\n\n// after\nint o = layoutManager.getOrientation();\nnew RecycleViewDivider(ctx,\n    o == RecyclerView.VERTICAL ? RecycleViewDivider.VERTICAL : RecycleViewDivider.HORIZONTAL,\n    R.drawable.div);","handlingStrategy":"validation","validationCode":"int o = (orientation == LinearLayout.VERTICAL)\n    ? RecycleViewDivider.VERTICAL\n    : RecycleViewDivider.HORIZONTAL;\nnew RecycleViewDivider(context, o, divider);","typeGuard":"private static boolean isValidDividerOrientation(int o) {\n    return o == RecycleViewDivider.HORIZONTAL || o == RecycleViewDivider.VERTICAL;\n}","tryCatchPattern":null,"preventionTips":["Pass RecycleViewDivider.HORIZONTAL/VERTICAL explicitly, not raw ints.","Validate any externally sourced orientation to {0,1} before constructing the divider.","Avoid confusing RecyclerView constants with the divider's constants."],"tags":["android","recyclerview","itemdecoration","argument"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}