DrKLO/Telegram · error · IllegalArgumentException

invalid orientation

Error message

invalid orientation

What it means

OrientationHelper.createOrientationHelper() is the factory used by layout managers to obtain a per-axis helper. Its switch covers only HORIZONTAL and VERTICAL; any other orientation falls through to an unconditional IllegalArgumentException('invalid orientation') with no value echo. This is a defensive guard: OrientationHelper cannot operate without a known axis.

Source

Thrown at TMessagesProj/src/main/java/androidx/recyclerview/widget/OrientationHelper.java:247

     */
    public abstract int getModeInOther();

    /**
     * Creates an OrientationHelper for the given LayoutManager and orientation.
     *
     * @param layoutManager LayoutManager to attach to
     * @param orientation   Desired orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}
     * @return A new OrientationHelper
     */
    public static OrientationHelper createOrientationHelper(
            RecyclerView.LayoutManager layoutManager, @RecyclerView.Orientation int orientation) {
        switch (orientation) {
            case HORIZONTAL:
                return createHorizontalHelper(layoutManager);
            case VERTICAL:
                return createVerticalHelper(layoutManager);
        }
        throw new IllegalArgumentException("invalid orientation");
    }

    /**
     * Creates a horizontal OrientationHelper for the given LayoutManager.
     *
     * @param layoutManager The LayoutManager to attach to.
     * @return A new OrientationHelper
     */
    public static OrientationHelper createHorizontalHelper(
            RecyclerView.LayoutManager layoutManager) {
        return new OrientationHelper(layoutManager) {
            @Override
            public int getEndAfterPadding() {
                return mLayoutManager.getWidth() - mLayoutManager.getPaddingRight();
            }

            @Override
            public int getEnd() {

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Fix the orientation at its origin — pass LinearLayoutManager.HORIZONTAL or VERTICAL.
  2. If writing a custom LayoutManager, use OrientationHelper.createHorizontalHelper / createVerticalHelper directly instead of the generic factory when the axis is known statically.
  3. Add a precondition check before createOrientationHelper so the bad value never reaches it.

Example fix

// before
OrientationHelper h = OrientationHelper.createOrientationHelper(this, axisFromConfig);

// after
int axis = (axisFromConfig == LinearLayoutManager.HORIZONTAL)
    ? LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL;
OrientationHelper h = OrientationHelper.createOrientationHelper(this, axis);
Defensive patterns

Strategy: validation

Validate before calling

static OrientationHelper safeHelper(RecyclerView.LayoutManager lm, int orientation) {
    switch (orientation) {
        case OrientationHelper.HORIZONTAL: return OrientationHelper.createHorizontalHelper(lm);
        case OrientationHelper.VERTICAL:   return OrientationHelper.createVerticalHelper(lm);
        default: throw new IllegalArgumentException("orientation must be HORIZONTAL or VERTICAL");
    }
}

Type guard

static boolean isValidOrientation(int o) {
    return o == OrientationHelper.HORIZONTAL || o == OrientationHelper.VERTICAL;
}

Try / catch

null

Prevention

When it happens

Trigger: An internal call path (usually setOrientation or LayoutManager construction) that supplies an int other than 0/1 to createOrientationHelper. A custom LayoutManager that builds its own OrientationHelper with a bad constant.

Common situations: Almost always a downstream symptom of error 21 (invalid orientation passed to LinearLayoutManager). A custom LayoutManager copied from a fork that uses different orientation constant values.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/f900ffef489737d8. Report an issue: GitHub.