{"record":{"id":"b5e96cd6ce5f1f4a","repo":"MuntashirAkon/AppManager","slug":"invalid-state-to-get-top-offset","errorCode":null,"errorMessage":"Invalid state to get top offset: ","messagePattern":"Invalid state to get top offset: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java","lineNumber":1796,"sourceCode":"        } else {\n            setStateInternal(state);\n        }\n    }\n\n    private int getTopOffsetForState(@StableState int state) {\n        switch (state) {\n            case STATE_COLLAPSED:\n                return collapsedOffset;\n            case STATE_EXPANDED:\n                return getExpandedOffset();\n            case STATE_HALF_EXPANDED:\n                return halfExpandedOffset;\n            case STATE_HIDDEN:\n                return parentHeight;\n            default:\n                // Fall through\n        }\n        throw new IllegalArgumentException(\"Invalid state to get top offset: \" + state);\n    }\n\n    private final ViewDragHelper.Callback dragCallback =\n            new ViewDragHelper.Callback() {\n\n                private long viewCapturedMillis;\n\n                @Override\n                public boolean tryCaptureView(@NonNull View child, int pointerId) {\n                    if (state == STATE_DRAGGING) {\n                        return false;\n                    }\n                    if (touchingScrollingChild) {\n                        return false;\n                    }\n                    if (state == STATE_EXPANDED && activePointerId == pointerId) {\n                        View scroll = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;\n                        if (scroll != null && scroll.canScrollVertically(-1)) {","sourceCodeStart":1778,"sourceCodeEnd":1814,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java#L1778-L1814","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom code reading offsets during a drag callback or before the behavior is attached; restoring an unsupported state value from saved instance state.","solutions":["Query offsets only when state is a stable state","Handle the transient states yourself (skip or interpolate) instead of calling the offset getter","Fix the state value before it reaches the behavior (validate restore input)"],"exampleFix":"// before\nint top = behaviorTopOffset(sheet, behavior.getState());\n// after\nint st = behavior.getState();\nint top = (st == STATE_DRAGGING || st == STATE_SETTLING) ? 0 : behaviorTopOffset(sheet, st);","handlingStrategy":"validation","validationCode":"int st = behavior.getState();\nboolean safe = st == STATE_COLLAPSED || st == STATE_EXPANDED || st == STATE_HIDDEN || st == STATE_HALF_EXPANDED;","typeGuard":"boolean isQueryableState(int s) { return s >= STATE_EXPANDED && s <= STATE_HIDDEN && s != STATE_DRAGGING && s != STATE_SETTLING; }","tryCatchPattern":"try {\n    topOffset = topOffsetFor(state);\n} catch (IllegalArgumentException e) {\n    topOffset = parentHeight; // safe default\n}","preventionTips":["Only compute offsets for stable states","Sanitize restored state values","Skip offset queries during drag/settle callbacks"],"tags":["android","bottomsheet","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}