material-components/material-components-android · error · IllegalStateException

minSeparation(%s) must be greater or equal to 0

Error message

minSeparation(%s) must be greater or equal to 0

What it means

Thrown by validateMinSeparation() when the minimum separation between neighboring thumbs (set via setMinSeparation) is negative. Min separation is only meaningful as zero or positive; a negative value indicates a caller error or a bad dimension resource.

Source

Thrown at lib/java/com/google/android/material/slider/BaseSlider.java:758

          String.format(EXCEPTION_ILLEGAL_VALUE_FROM, valueFrom, valueTo));
    }

    for (Float value : values) {
      if (value < valueFrom || value > valueTo) {
        throw new IllegalStateException(
            String.format(EXCEPTION_ILLEGAL_VALUE, value, valueFrom, valueTo));
      }
      if (stepSize > 0.0f && !valueLandsOnTick(value)) {
        throw new IllegalStateException(
            String.format(EXCEPTION_ILLEGAL_DISCRETE_VALUE, value, valueFrom, stepSize, stepSize));
      }
    }
  }

  private void validateMinSeparation() {
    final float minSeparation = getMinSeparation();
    if (minSeparation < 0) {
      throw new IllegalStateException(
          String.format(EXCEPTION_ILLEGAL_MIN_SEPARATION, minSeparation));
    }
    if (stepSize > 0 && minSeparation > 0) {
      if (separationUnit != UNIT_VALUE) {
        throw new IllegalStateException(
            String.format(
                EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE_UNIT, minSeparation, stepSize));
      }
      if (minSeparation < stepSize || !isMultipleOfStepSize(minSeparation)) {
        throw new IllegalStateException(
            String.format(
                EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE, minSeparation, stepSize, stepSize));
      }
    }
  }

  private void warnAboutFloatingPointError() {
    if (stepSize == 0) {

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Pass 0 or a positive value to setMinSeparation.
  2. Math.max(0, computedSeparation) before calling the setter.
  3. Check the app:minSeparation attribute in the layout XML for negative values.
  4. Recompute separation relative to (valueTo - valueFrom) if it depends on the range.

Example fix

// before
slider.setMinSeparation(-2f);

// after
slider.setMinSeparation(Math.max(0f, computedSeparation));
Defensive patterns

Strategy: validation

Validate before calling

float safeSep = Math.max(0f, computedSeparation);
slider.setMinSeparation(safeSep);

Prevention

When it happens

Trigger: Calling setMinSeparation(-n) or setMinSeparationDimension with a negative dimension; XML app:minSeparation set to a negative value; computing separation from user input without validation.

Common situations: Deriving minSeparation from a formula (e.g. step or range percentage) that can go negative on edge-case inputs; passing a negative pixel dimension from a design token or dimen resource.

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/7292d84e5627d3f3. Report an issue: GitHub.