{"record":{"id":"10961508a2d9efef","repo":"material-components/material-components-android","slug":"invalid-state-to-get-swipe-offset","errorCode":null,"errorMessage":"Invalid state to get swipe offset: {}","messagePattern":"Invalid state to get swipe offset: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/listitem/ListItemLayout.java","lineNumber":701,"sourceCode":"    } else {\n      return swipeToRevealLayoutRight instanceof RevealableListItem;\n    }\n  }\n\n  private int getOffsetForSwipeState(\n      @StableSwipeState int swipeState, @RevealGravity int revealGravity) {\n    if (!swipeToRevealLayoutExistsForGravity(revealGravity)) {\n      throw new IllegalArgumentException(\"No RevealableListItem with gravity \" + revealGravity);\n    }\n    switch (swipeState) {\n      case STATE_CLOSED:\n        return getSwipeViewClosedOffset();\n      case STATE_OPEN:\n        return getSwipeRevealViewRevealedOffset(revealGravity);\n      case STATE_SWIPE_PRIMARY_ACTION:\n        return getSwipeToActionOffset(revealGravity);\n      default:\n        throw new IllegalArgumentException(\"Invalid state to get swipe offset: \" + swipeState);\n    }\n  }\n\n  private void updateSwipeProgress(int left) {\n    if (!(contentView instanceof SwipeableListItem && swipeToRevealLayoutExists())) {\n      return;\n    }\n    revealViewOffset = left - originalContentViewLeft;\n    boolean revealingLeft = revealViewOffset > 0;\n    boolean revealingRight = revealViewOffset < 0;\n\n    // Update the activeSwipeToRevealLayout\n    if (revealingLeft && swipeToRevealLayoutLeft instanceof RevealableListItem) {\n      activeSwipeToRevealLayout = (RevealableListItem) swipeToRevealLayoutLeft;\n    } else if (revealingRight && swipeToRevealLayoutRight instanceof RevealableListItem) {\n      activeSwipeToRevealLayout = (RevealableListItem) swipeToRevealLayoutRight;\n    }\n","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/listitem/ListItemLayout.java#L683-L719","documentation":"Inside getOffsetForSwipeState, after the gravity check, a switch maps the swipe state to an offset: STATE_CLOSED, STATE_OPEN, or STATE_SWIPE_PRIMARY_ACTION. Any other int reaches the default branch and throws IllegalArgumentException with the offending value — this guards against unknown/invalid state constants reaching internal offset math.","triggerScenarios":"Passing a raw int or a stale constant from a different class (e.g. a copied constant whose value changed between library versions) as swipeState; subclass or reflection code invoking the internal method with an arbitrary value.","commonSituations":"Version upgrades where state constant values changed; mixing app-defined state ints with SwipeableListItem states; copying sample code from an older library revision.","solutions":["Use only the declared constants: SwipeableListItem.STATE_CLOSED, STATE_OPEN, STATE_SWIPE_PRIMARY_ACTION.","Reference constants symbolically (SwipeableListItem.STATE_*) instead of literal numbers so library updates stay compatible.","If persisting state across process restarts, map stored values through a whitelist to the current constants before use."],"exampleFix":"// before\nlistItemLayout.setSwipeState(2 /* hardcoded from old sample */, gravity, true);\n\n// after\nlistItemLayout.setSwipeState(SwipeableListItem.STATE_SWIPE_PRIMARY_ACTION, gravity, true);","handlingStrategy":"validation","validationCode":"static boolean isValidSwipeState(int s) {\n  return s == SwipeableListItem.STATE_CLOSED\n      || s == SwipeableListItem.STATE_OPEN\n      || s == SwipeableListItem.STATE_SWIPE_PRIMARY_ACTION;\n}\nif (!isValidSwipeState(state)) state = SwipeableListItem.STATE_CLOSED;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference constants symbolically; never persist raw state ints without whitelisting.","After library upgrades, re-verify constant values used in saved state.","Annotate internal params with @StableSwipeState to get lint coverage."],"tags":["material-components","listitem","swipe","state-machine"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}