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

  1. Use a non-negative dimension for indicatorTrackGapSize
  2. Clamp computed gap values: max(0, computedGap)
  3. 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

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


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