{"record":{"id":"e9d1acbd05a87b59","repo":"MuntashirAkon/AppManager","slug":"state-dragging-should-not-be-set-externally-state-settling","errorCode":null,"errorMessage":"STATE_DRAGGING should not be set externally.|STATE_SETTLING should not be set externally.","messagePattern":"STATE_DRAGGING should not be set externally\\.\\|STATE_SETTLING should not be set externally\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java","lineNumber":1316,"sourceCode":"    /**\n     * Removes a previously added callback.\n     *\n     * @param callback The callback to remove.\n     */\n    public void removeBottomSheetCallback(@NonNull BottomSheetCallback callback) {\n        callbacks.remove(callback);\n    }\n\n    /**\n     * Sets the state of the bottom sheet. The bottom sheet will transition to that state with\n     * animation.\n     *\n     * @param state One of {@link #STATE_COLLAPSED}, {@link #STATE_EXPANDED}, {@link #STATE_HIDDEN},\n     *     or {@link #STATE_HALF_EXPANDED}.\n     */\n    public void setState(@StableState int state) {\n        if (state == STATE_DRAGGING || state == STATE_SETTLING) {\n            throw new IllegalArgumentException(\n                    \"STATE_\"\n                            + (state == STATE_DRAGGING ? \"DRAGGING\" : \"SETTLING\")\n                            + \" should not be set externally.\");\n        }\n        if (!hideable && state == STATE_HIDDEN) {\n            Log.w(TAG, \"Cannot set state: \" + state);\n            return;\n        }\n        final int finalState;\n        if (state == STATE_HALF_EXPANDED\n                && fitToContents\n                && getTopOffsetForState(state) <= fitToContentsOffset) {\n            // Skip to the expanded state if we would scroll past the height of the contents.\n            finalState = STATE_EXPANDED;\n        } else {\n            finalState = state;\n        }\n        if (viewRef == null || viewRef.get() == null) {","sourceCodeStart":1298,"sourceCodeEnd":1334,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java#L1298-L1334","documentation":"setState() only accepts stable states (COLLAPSED, EXPANDED, HIDDEN, HALF_EXPANDED). STATE_DRAGGING and STATE_SETTLING are transient internal states managed by the drag helper; setting them externally is invalid, so the behavior throws IllegalArgumentException naming the offending state.","triggerScenarios":"Calling behavior.setState(BottomSheetBehavior.STATE_DRAGGING) or setState(STATE_SETTLING), or passing an int variable that happens to hold a transient state.","commonSituations":"Persistence/restore code saving state as an int and re-applying it; loops iterating over all STATE_* constants; animating by setting dragging state manually.","solutions":["Only pass stable states (COLLAPSED/EXPANDED/HIDDEN/HALF_EXPANDED)","Filter transient states out before calling setState, e.g. skip DRAGGING/SETTLING","Let the behavior's internal drag controller manage transient states"],"exampleFix":"// before\nbehavior.setState(savedState);\n// after\nif (savedState != STATE_DRAGGING && savedState != STATE_SETTLING) {\n    behavior.setState(savedState);\n}","handlingStrategy":"validation","validationCode":"if (state != STATE_DRAGGING && state != STATE_SETTLING) behavior.setState(state);","typeGuard":"boolean isStableState(int s) { return s == STATE_COLLAPSED || s == STATE_EXPANDED || s == STATE_HIDDEN || s == STATE_HALF_EXPANDED; }","tryCatchPattern":"try {\n    behavior.setState(state);\n} catch (IllegalArgumentException e) {\n    // ignore transient states\n}","preventionTips":["Never persist or reapply transient states","Whitelist stable states when restoring UI state","Let the drag controller manage DRAGGING/SETTLING"],"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"}