{"record":{"id":"daa8f13c82838646","repo":"material-components/material-components-android","slug":"invalid-orientation","errorCode":null,"errorMessage":"invalid orientation:","messagePattern":"invalid orientation:","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/carousel/CarouselLayoutManager.java","lineNumber":1631,"sourceCode":"  /**\n   * Returns the current orientation of the layout.\n   *\n   * @return Current orientation, either {@link #HORIZONTAL} or {@link #VERTICAL}\n   * @see #setOrientation(int)\n   */\n  @RecyclerView.Orientation\n  public int getOrientation() {\n    return orientationHelper.orientation;\n  }\n\n  /**\n   * Sets the orientation of the layout.\n   *\n   * @param orientation {@link #HORIZONTAL} or {@link #VERTICAL}\n   */\n  public void setOrientation(@RecyclerView.Orientation int orientation) {\n    if (orientation != HORIZONTAL && orientation != VERTICAL) {\n      throw new IllegalArgumentException(\"invalid orientation:\" + orientation);\n    }\n\n    assertNotInLayoutOrScroll(null);\n\n    if (orientationHelper == null || orientation != orientationHelper.orientation) {\n      orientationHelper = CarouselOrientationHelper.createOrientationHelper(this, orientation);\n      refreshKeylineState();\n    }\n  }\n\n  @Override\n  public void onItemsAdded(@NonNull RecyclerView recyclerView, int positionStart, int itemCount) {\n    super.onItemsAdded(recyclerView, positionStart, itemCount);\n    updateItemCount();\n  }\n\n  @Override\n  public void onItemsRemoved(@NonNull RecyclerView recyclerView, int positionStart, int itemCount) {","sourceCodeStart":1613,"sourceCodeEnd":1649,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/carousel/CarouselLayoutManager.java#L1613-L1649","documentation":"CarouselLayoutManager.setOrientation (CarouselLayoutManager.java:1631) only accepts RecyclerView.HORIZONTAL (0) or RecyclerView.VERTICAL (1); any other int throws IllegalArgumentException with the offending value in the message. This mirrors LinearLayoutManager's long-standing validation, but note that unlike some RecyclerView components there is no 'defValue' fallback — the invalid value fails immediately.","triggerScenarios":"Calling setOrientation with a hardcoded number other than 0/1, or reading an orientation from an external source (config, JSON, intent extra, saved state) and passing it through unvalidated. The annotated @RecyclerView.Orientation parameter is compile-time only — Kotlin or reflection call sites bypass it.","commonSituations":"Parsing orientation from a remote-config flag or deep link where the value is out of range (e.g. 2, -1). Refactoring constants and accidentally passing LinearLayoutManager.HORIZONTAL-like unrelated ints. Crash message 'invalid orientation: 2' makes this one easy to diagnose.","solutions":["Pass only RecyclerView.HORIZONTAL or RecyclerView.VERTICAL constants.","Sanitize external values before use: map anything unexpected to a default orientation.","If the value comes from saved state, validate before restoring it into the layout manager."],"exampleFix":"// before\nlayoutManager.setOrientation(intent.getIntExtra(\"orientation\", 2));\n\n// after\nint raw = intent.getIntExtra(\"orientation\", RecyclerView.HORIZONTAL);\nint orientation = (raw == RecyclerView.VERTICAL) ? RecyclerView.VERTICAL : RecyclerView.HORIZONTAL;\nlayoutManager.setOrientation(orientation);","handlingStrategy":"validation","validationCode":"int safe = (orientation == RecyclerView.VERTICAL) ? RecyclerView.VERTICAL : RecyclerView.HORIZONTAL;\nlayoutManager.setOrientation(safe);","typeGuard":"static boolean isValidOrientation(int o) {\n  return o == RecyclerView.HORIZONTAL || o == RecyclerView.VERTICAL;\n}","tryCatchPattern":null,"preventionTips":["Only pass RecyclerView orientation constants, never raw ints.","Validate values from remote config/intents/saved state before use.","Unit-test any orientation-mapping code with out-of-range inputs."],"tags":["android","material-components","carousel","recyclerview","argument-validation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}