{"record":{"id":"dd9af51c3f239b1b","repo":"material-components/material-components-android","slug":"invalid-orientation-it-should-be-either-horiz","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/java/com/google/android/material/divider/MaterialDividerItemDecoration.java","lineNumber":126,"sourceCode":"\n    dividerDrawable = new ShapeDrawable();\n    setDividerColor(color);\n    setOrientation(orientation);\n  }\n\n  /**\n   * Sets the orientation for this divider. This should be called if {@link\n   * RecyclerView.LayoutManager} changes orientation.\n   *\n   * <p>A {@link #HORIZONTAL} orientation will draw a vertical divider, and a {@link #VERTICAL}\n   * orientation a horizontal divider.\n   *\n   * @param orientation The orientation of the {@link RecyclerView} this divider is associated with:\n   *     {@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: \" + orientation + \". It should be either HORIZONTAL or VERTICAL\");\n    }\n    this.orientation = orientation;\n  }\n\n  public int getOrientation() {\n    return orientation;\n  }\n\n  /**\n   * Sets the thickness of the divider.\n   *\n   * @param thickness The thickness value to be set.\n   * @see #getDividerThickness()\n   * @attr ref com.google.android.material.R.styleable#MaterialDivider_dividerThickness\n   */\n  public void setDividerThickness(@Px int thickness) {\n    this.thickness = thickness;","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/divider/MaterialDividerItemDecoration.java#L108-L144","documentation":"MaterialDividerItemDecoration.setOrientation(int) accepts only the constants HORIZONTAL (vertical divider line) or VERTICAL (horizontal divider line), matching the orientation of the RecyclerView's LayoutManager. Any other int — including the LayoutManager's own constants or an uninitialized field — throws IllegalArgumentException to prevent silently drawing dividers in the wrong direction.","triggerScenarios":"Calling setOrientation(0) / setOrientation(1) with hardcoded values that map to the wrong constants; passing LinearLayoutManager.HORIZONTAL to the decoration but mixing up constant sources; calling setOrientation with a value read from a config/bundle that can be absent (default 0 or -1); reacting to onConfigurationChanged with a computed orientation that is neither constant.","commonSituations":"Copy-pasting sample code that uses raw ints; switching between divider classes (DividerItemDecoration vs MaterialDividerItemDecoration) whose constant values differ; handling layout direction changes yourself instead of letting the decoration read it.","solutions":["Pass only MaterialDividerItemDecoration.HORIZONTAL or MaterialDividerItemDecoration.VERTICAL — use the LayoutManager orientation: decoration.setOrientation(layoutManager.getOrientation());","Default any persisted/config-sourced orientation to a valid constant before calling setOrientation (e.g.VERTICAL if value is neither).","Remove hardcoded 0/1 literals and reference the class constants so refactors stay safe."],"exampleFix":"// before\ndividerItemDecoration.setOrientation(orientationFromPrefs); // may be -1/0 unexpectedly\n\n// after\nint orientation = (orientationFromPrefs == MaterialDividerItemDecoration.HORIZONTAL)\n    ? MaterialDividerItemDecoration.HORIZONTAL\n    : MaterialDividerItemDecoration.VERTICAL;\ndividerItemDecoration.setOrientation(orientation);","handlingStrategy":"validation","validationCode":"int orientation = (value == MaterialDividerItemDecoration.HORIZONTAL\n    || value == MaterialDividerItemDecoration.VERTICAL)\n        ? value : MaterialDividerItemDecoration.VERTICAL;\ndivider.setOrientation(orientation);","typeGuard":null,"tryCatchPattern":"try { divider.setOrientation(raw); } catch (IllegalArgumentException e) { divider.setOrientation(LinearLayoutManager.getOrientation()); }","preventionTips":["Always source orientation from layoutManager.getOrientation(), never from persisted raw ints.","Ban magic numbers 0/1; use the class constants.","Default config-driven orientation values to a valid constant at load time."],"tags":["material-components","recyclerview","divider","orientation","validation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}