{"record":{"id":"68e0f43a4e1a2794","repo":"material-components/material-components-android","slug":"at-least-one-value-must-be-set","errorCode":null,"errorMessage":"At least one value must be set","messagePattern":"At least one value must be set","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/slider/BaseSlider.java","lineNumber":912,"sourceCode":"   * <p>If the slider is in discrete mode (i.e. the tick increment value is greater than 0), the\n   * values must be set to a value falls on a tick (i.e.: {@code value == valueFrom + x * stepSize},\n   * where {@code x} is an integer equal to or greater than 0). If that is not the case, an {@link\n   * IllegalStateException} will be thrown when the view is laid out.\n   *\n   * @param values An array of values to set.\n   * @throws IllegalArgumentException If {@code values} is empty.\n   */\n  void setValues(@NonNull List<Float> values) {\n    setValuesInternal(new ArrayList<>(values));\n  }\n\n  /**\n   * This method assumes the list passed in is a copy. It is split out so we can call it from {@link\n   * #setValues(Float...)} and {@link #setValues(List)}\n   */\n  private void setValuesInternal(@NonNull ArrayList<Float> values) {\n    if (values.isEmpty()) {\n      throw new IllegalArgumentException(\"At least one value must be set\");\n    }\n\n    Collections.sort(values);\n\n    if (this.values.size() == values.size()) {\n      if (this.values.equals(values)) {\n        return;\n      }\n    }\n\n    this.values = values;\n    dirtyConfig = true;\n    updateDefaultThumbDrawables();\n    // Only update the focused thumb index. The active thumb index will be updated on touch.\n    focusedThumbIdx = 0;\n    updateHaloHotspot();\n    createLabelPool();\n    dispatchOnChangedProgrammatically();","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/slider/BaseSlider.java#L894-L930","documentation":"IllegalArgumentException thrown immediately by setValuesInternal() when setValues(List) or setValues(Float...) is called with an empty collection. A slider needs at least one thumb/value to render, so empty input is rejected synchronously (unlike the layout-time validations).","triggerScenarios":"slider.setValues() with an empty varargs call is a compile issue, but setValues(Collections.emptyList()) or setValues(emptyListFromApi) throws; passing a filtered list that happened to become empty.","commonSituations":"Loading thumb values from a database/network response that returns no rows; filter pipelines (map/filter) producing an empty list before setting values.","solutions":["Guard the call: only invoke setValues(list) when !list.isEmpty().","Default to a single value (e.g. the current value or valueFrom) when the source list is empty.","Fix the data source so at least one value is always produced."],"exampleFix":"// before\nslider.setValues(valuesFromDb); // crashes when list is empty\n\n// after\nif (!valuesFromDb.isEmpty()) {\n  slider.setValues(valuesFromDb);\n} else {\n  slider.setValues(slider.getValueFrom());\n}","handlingStrategy":"validation","validationCode":"if (!values.isEmpty()) {\n  slider.setValues(values);\n} else {\n  slider.setValues(slider.getValueFrom());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assume a data source returns at least one row.","Default to a single thumb value when the source list is empty."],"tags":["android","slider","material-components","validation","immediate"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}