MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid state to get top offset:

Error message

Invalid state to get top offset: 

What it means

Internal top-offset calculation maps the current state to a pixel offset; if the state is none of COLLAPSED, HALF_EXPANDED, EXPANDED, HIDDEN (or the known set handled by the switch), it throws IllegalArgumentException("Invalid state to get top offset: " + state). This guards against an unknown/transient state reaching layout math.

Solutions

  1. Query offsets only when state is a stable state
  2. Handle the transient states yourself (skip or interpolate) instead of calling the offset getter
  3. Fix the state value before it reaches the behavior (validate restore input)

Example fix

// before
int top = behaviorTopOffset(sheet, behavior.getState());
// after
int st = behavior.getState();
int top = (st == STATE_DRAGGING || st == STATE_SETTLING) ? 0 : behaviorTopOffset(sheet, st);
Defensive patterns

Strategy: validation

Validate before calling

int st = behavior.getState();
boolean safe = st == STATE_COLLAPSED || st == STATE_EXPANDED || st == STATE_HIDDEN || st == STATE_HALF_EXPANDED;

Type guard

boolean isQueryableState(int s) { return s >= STATE_EXPANDED && s <= STATE_HIDDEN && s != STATE_DRAGGING && s != STATE_SETTLING; }

Try / catch

try {
    topOffset = topOffsetFor(state);
} catch (IllegalArgumentException e) {
    topOffset = parentHeight; // safe default
}

Prevention

When it happens

Trigger: Requesting a top offset while the sheet is in STATE_DRAGGING or STATE_SETTLING, or after state was corrupted to an out-of-range value.

Common situations: Custom code reading offsets during a drag callback or before the behavior is attached; restoring an unsupported state value from saved instance state.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/b5e96cd6ce5f1f4a. Report an issue: GitHub.

Appendix: source

Thrown at libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java:1796

        } else {
            setStateInternal(state);
        }
    }

    private int getTopOffsetForState(@StableState int state) {
        switch (state) {
            case STATE_COLLAPSED:
                return collapsedOffset;
            case STATE_EXPANDED:
                return getExpandedOffset();
            case STATE_HALF_EXPANDED:
                return halfExpandedOffset;
            case STATE_HIDDEN:
                return parentHeight;
            default:
                // Fall through
        }
        throw new IllegalArgumentException("Invalid state to get top offset: " + state);
    }

    private final ViewDragHelper.Callback dragCallback =
            new ViewDragHelper.Callback() {

                private long viewCapturedMillis;

                @Override
                public boolean tryCaptureView(@NonNull View child, int pointerId) {
                    if (state == STATE_DRAGGING) {
                        return false;
                    }
                    if (touchingScrollingChild) {
                        return false;
                    }
                    if (state == STATE_EXPANDED && activePointerId == pointerId) {
                        View scroll = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;
                        if (scroll != null && scroll.canScrollVertically(-1)) {

View on GitHub (pinned to 0152f468fc)