{"record":{"id":"0579cec86d0d839d","repo":"material-components/material-components-android","slug":"not-enough-labels-d-to-display-all-the-values-d","errorCode":null,"errorMessage":"Not enough labels(%d) to display all the values(%d)","messagePattern":"Not enough labels\\((.+?)\\) to display all the values\\((.+?)\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/slider/BaseSlider.java","lineNumber":3832,"sourceCode":"      labelsInAnimator = createLabelAnimator(true);\n      labelsOutAnimator = null;\n      labelsInAnimator.start();\n    }\n\n    Iterator<TooltipDrawable> labelItr = labels.iterator();\n\n    if (showLabelOnAllThumbs) {\n      for (int i = 0; i < values.size() && labelItr.hasNext(); i++) {\n        if (i == focusedThumbIdx) {\n          // We position the focused thumb last so it's displayed on top, so skip it for now.\n          continue;\n        }\n        setValueForLabel(labelItr.next(), values.get(i));\n      }\n    }\n\n    if (!labelItr.hasNext()) {\n      throw new IllegalStateException(\n          String.format(\n              \"Not enough labels(%d) to display all the values(%d)\", labels.size(), values.size()));\n    }\n\n    // Now set the label for the focused thumb so it's on top.\n    setValueForLabel(labelItr.next(), values.get(focusedThumbIdx));\n  }\n\n  private String formatValue(float value) {\n    if (hasLabelFormatter()) {\n      return formatter.getFormattedValue(value);\n    }\n\n    return String.format((int) value == value ? \"%.0f\" : \"%.2f\", value);\n  }\n\n  private void setValueForLabel(TooltipDrawable label, float value) {\n    label.setText(formatValue(value));","sourceCodeStart":3814,"sourceCodeEnd":3850,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/slider/BaseSlider.java#L3814-L3850","documentation":"IllegalStateException thrown in the label-assignment loop when the internal label pool runs out before every thumb (ending with the focused thumb) got a label. Labels are created lazily into a pool sized by the slider itself, so in practice this is an internal invariant violation — most often seen when values were mutated without the label pool being rebuilt, or in custom subclasses that interfere with label handling.","triggerScenarios":"Having more thumbs/values than pooled labels after in-place mutation of the values list (e.g. obtaining getValues() and modifying it), or subclassing BaseSlider and overriding label behavior/values handling inconsistently.","commonSituations":"Custom slider subclasses (e.g. custom RangeSlider variants) that bypass setValues(); rare version-specific regressions in the label pool logic — check the Material Components changelog if it reproduces with plain Slider usage.","solutions":["Never mutate the list returned by getValues(); always call setValues() with a new list.","In custom subclasses, delegate value changes to setValues() so dirtyConfig and the label pool stay consistent.","If it reproduces with stock Slider, upgrade (or pin) the Material Components version and report it with the exact configuration."],"exampleFix":"// before\nslider.getValues().add(5f); // in-place mutation desyncs internal label count\n\n// after\nList<Float> vals = new ArrayList<>(slider.getValues());\nvals.add(5f);\nslider.setValues(vals);","handlingStrategy":"try-catch","validationCode":"List<Float> vals = new ArrayList<>(slider.getValues());\nvals.add(newValue);\nslider.setValues(vals); // keeps label pool in sync with value count","typeGuard":null,"tryCatchPattern":"Wrap interaction-triggered show paths defensively in custom subclasses: try { slider.onDraw(...) } catch (IllegalStateException e) { Log.e(TAG, \"label/value desync\", e); } — but fix the root cause (never mutate getValues() in place).","preventionTips":["Never mutate the list returned by getValues(); build a copy and call setValues().","In subclasses, route all value changes through setValues().","If stock Slider hits this, pin/upgrade the Material Components version and report it."],"tags":["android","slider","material-components","invariant","internal"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}