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
- Pass 0 or a positive value to setMinSeparation.
- Math.max(0, computedSeparation) before calling the setter.
- Check the app:minSeparation attribute in the layout XML for negative values.
- 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
- Treat 0 as the 'no separation' sentinel, never a negative number.
- Audit XML app:minSeparation values in code review.
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
- minSeparation(%s) cannot be set as a dimension when using st
- minSeparation(%s) must be greater or equal and a multiple of
- valueFrom(%s) must be smaller than valueTo(%s)
- Slider value(%s) must be greater or equal to valueFrom(%s),
- %1$s requires a value for the %2$s attribute to be set in yo
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/7292d84e5627d3f3.
Report an issue: GitHub.