material-components/material-components-android · error · IllegalArgumentException
indicatorTrackGapSize must be >= 0.
Error message
indicatorTrackGapSize must be >= 0.
What it means
BaseProgressIndicatorSpec.validateSpec throws IllegalArgumentException when indicatorTrackGapSize is negative. The gap between the track segments (or between track and stop indicator) is a dimension; a negative value is meaningless and breaks layout math, so spec validation rejects it eagerly.
Source
Thrown at lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java:294
public int getTrackCornerRadiusInPx() {
return useRelativeTrackCornerRadius
? (int) (trackThickness * trackCornerRadiusFraction)
: trackCornerRadius;
}
/**
* Returns true if the stroke ROUND cap should be used to prevent artifacts like (b/319309456),
* when fully rounded corners are specified.
*/
public boolean useStrokeCap() {
return useRelativeTrackCornerRadius && trackCornerRadiusFraction == 0.5f;
}
@CallSuper
void validateSpec() {
if (indicatorTrackGapSize < 0) {
// Throws an exception if trying to use a negative gap size.
throw new IllegalArgumentException("indicatorTrackGapSize must be >= 0.");
}
}
}
View on GitHub (pinned to ac7e18efee)
Solutions
- Use a non-negative dimension for indicatorTrackGapSize
- Clamp computed gap values: max(0, computedGap)
- On small screens consider 0 gap or hiding the stop indicator instead of negative spacing
Example fix
<!-- before -->
<com.google.android.material.progressindicator.LinearProgressIndicator
app:indicatorTrackGapSize="-4dp" ... />
<!-- after -->
<com.google.android.material.progressindicator.LinearProgressIndicator
app:indicatorTrackGapSize="4dp" ... /> Defensive patterns
Strategy: validation
Validate before calling
fun safeGapSize(desired: Int): Int = desired.coerceAtLeast(0)
Try / catch
catch (e: IllegalArgumentException) { Log.e(TAG, "Negative track gap; resetting to 0", e); spec.indicatorTrackGapSize = 0 } Prevention
- Clamp computed gap dimensions to >= 0
- Test layouts on small screens where subtraction can go negative
- Keep dimension resources non-negative by convention
When it happens
Trigger: Setting app:indicatorTrackGapSize (or trackStopIndicatorSize related gap specs) to a negative dimension; computing the gap dynamically and passing a negative result via programmatic spec mutation; using a dimension resource with a negative value.
Common situations: Calculated gap = availableWidth - (needed sizes) going negative on small screens; negative dimension in resources; copy-paste of stop-indicator sample values with a sign error.
Related errors
- The component's visibility must be one of VISIBLE, INVISIBLE
- There must be a keyline marked as focal.
- No color resources provided for harmonization.
- Theme overlay should be used with the accompanying int[] att
- start Month cannot be after current Month
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/60b0654d380bf920.
Report an issue: GitHub.