{"record":{"id":"cc47436560d4e095","repo":"material-components/material-components-android","slug":"unexpected-value-s","errorCode":null,"errorMessage":"Unexpected value: %s","messagePattern":"Unexpected value: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java","lineNumber":469,"sourceCode":"    return innerMargin;\n  }\n\n  private int calculateCurrentOffset(int savedOuterEdge, V child) {\n    int currentOffset;\n\n    switch (state) {\n      case STATE_EXPANDED:\n        currentOffset = 0;\n        break;\n      case STATE_DRAGGING:\n      case STATE_SETTLING:\n        currentOffset = savedOuterEdge - sheetDelegate.getOuterEdge(child);\n        break;\n      case STATE_HIDDEN:\n        currentOffset = sheetDelegate.getHiddenOffset();\n        break;\n      default:\n        throw new IllegalStateException(\"Unexpected value: \" + state);\n    }\n    return currentOffset;\n  }\n\n  @Override\n  public boolean onInterceptTouchEvent(\n      @NonNull CoordinatorLayout parent, @NonNull V child, @NonNull MotionEvent event) {\n    if (!shouldInterceptTouchEvent(child)) {\n      ignoreEvents = true;\n      return false;\n    }\n    int action = event.getActionMasked();\n    // Record the velocity\n    if (action == MotionEvent.ACTION_DOWN) {\n      resetVelocity();\n    }\n    if (velocityTracker == null) {\n      velocityTracker = VelocityTracker.obtain();","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java#L451-L487","documentation":"SideSheetBehavior's saved-state offset calculation throws IllegalStateException for a state outside {STATE_EXPANDED, STATE_DRAGGING, STATE_SETTLING, STATE_HIDDEN}. The switch has no default handling for other ints, which almost always means a corrupted or hand-constructed saved-state / unstable state value rather than normal library flow.","triggerScenarios":"Restoring a SideSheetBehavior.SavedState written with parceling bugs, or calling internal state APIs with an arbitrary int; also reachable from code that writes STATE_DRAGGING-like custom constants into the behavior's state.","commonSituations":"Custom Parcelable for a screen that manually serializes sheet state and deserializes an invalid int; process-death restore where a stale version of the saved state format is read; reflective or state-injection tricks used in tests.","solutions":["Only ever set states via setState(STATE_EXPANDED / STATE_HIDDEN) and let the library persist its own SavedState.","If you persist state yourself, store only stable states and rehydrate by calling setState() with a valid constant.","For tests, use the library's constants instead of raw ints."],"exampleFix":"// before\noutState.putInt(\"sheet_state\", currentCustomStateInt); // may hold invalid value\n...\nbehavior.setState(restoredInt);\n\n// after\noutState.putBoolean(\"sheet_expanded\", behavior.getState() == BottomSheetBehavior.STATE_EXPANDED);\n...\nbehavior.setState(restoredExpanded ? BottomSheetBehavior.STATE_EXPANDED\n                                   : BottomSheetBehavior.STATE_HIDDEN);","handlingStrategy":"validation","validationCode":"static boolean isKnownSheetState(int state) {\n  return state == BottomSheetBehavior.STATE_EXPANDED\n      || state == BottomSheetBehavior.STATE_DRAGGING\n      || state == BottomSheetBehavior.STATE_SETTLING\n      || state == BottomSheetBehavior.STATE_HIDDEN;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let the behavior save/restore its own SavedState instead of hand-parceling state ints.","When persisting manually, store booleans or enum names, then map to library constants on restore."],"tags":["android","material-components","sidesheet","state-restoration"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}