{"record":{"id":"c2e1b77415440b62","repo":"material-components/material-components-android","slug":"unexpected-labelbehavior","errorCode":null,"errorMessage":"Unexpected labelBehavior: ","messagePattern":"Unexpected labelBehavior: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/slider/BaseSlider.java","lineNumber":3729,"sourceCode":"        ensureLabelsRemoved();\n        break;\n      case LABEL_VISIBLE:\n        if (isEnabled() && isSliderVisibleOnScreen()) {\n          ensureLabelsAdded(/* showLabelOnAllThumbs= */ true);\n        } else {\n          ensureLabelsRemoved();\n        }\n        break;\n      case LABEL_FLOATING:\n      case LABEL_WITHIN_BOUNDS:\n        if (activeThumbIdx != -1 && isEnabled()) {\n          ensureLabelsAdded(/* showLabelOnAllThumbs= */ false);\n        } else {\n          ensureLabelsRemoved();\n        }\n        break;\n      default:\n        throw new IllegalArgumentException(\"Unexpected labelBehavior: \" + labelBehavior);\n    }\n  }\n\n  private void updateLabelPivots() {\n    // Set the pivot point so that the label pops up in the direction from the thumb.\n    final float labelPivotX;\n    final float labelPivotY;\n\n    final boolean isVertical = isVertical();\n    final boolean isRtl = isRtl();\n    if (isVertical && isRtl) {\n      labelPivotX = RIGHT_LABEL_PIVOT_X;\n      labelPivotY = RIGHT_LABEL_PIVOT_Y;\n    } else if (isVertical) {\n      labelPivotX = LEFT_LABEL_PIVOT_X;\n      labelPivotY = LEFT_LABEL_PIVOT_Y;\n    } else {\n      labelPivotX = TOP_LABEL_PIVOT_X;","sourceCodeStart":3711,"sourceCodeEnd":3747,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/slider/BaseSlider.java#L3711-L3747","documentation":"IllegalArgumentException thrown in the label-show/hide dispatch switch when labelBehavior is not one of LABEL_GONE, LABEL_FLOATING, or LABEL_WITHIN_BOUNDS. Like the tick mode switch, this default arm is only reachable when a non-IntDef int was forced into setLabelBehavior, and it fires during interaction/layout when labels are added or removed.","triggerScenarios":"setLabelBehavior(arbitraryInt) from an untyped source (prefs, Intent extra, remote config), then dragging a thumb or focusing it so ensureLabelsAdded/Removed dispatch runs.","commonSituations":"Persisting label behavior as a raw int across app/library versions; A/B tests or remote-config flags mapped to ints by hand.","solutions":["Only pass Slider.LABEL_* constants to setLabelBehavior.","Validate and sanitize persisted ints against the known set before applying, with a sane default (LABEL_FLOATING).","Store a stable string key instead of the raw ordinal/int value."],"exampleFix":"// before\nslider.setLabelBehavior(behaviorFromRemoteConfig); // arbitrary int\n\n// after\nint b = behaviorFromRemoteConfig;\nslider.setLabelBehavior(\n    (b == Slider.LABEL_GONE || b == Slider.LABEL_FLOATING || b == Slider.LABEL_WITHIN_BOUNDS)\n        ? b : Slider.LABEL_FLOATING);","handlingStrategy":"validation","validationCode":"static boolean isValidLabelBehavior(int b) {\n  return b == Slider.LABEL_GONE || b == Slider.LABEL_FLOATING || b == Slider.LABEL_WITHIN_BOUNDS;\n}\nslider.setLabelBehavior(isValidLabelBehavior(b) ? b : Slider.LABEL_FLOATING);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only LABEL_* constants through typed variables; avoid raw ints from remote config.","Validate persisted behavior values on restore and default to LABEL_FLOATING."],"tags":["android","slider","material-components","invariant","interaction"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}