{"record":{"id":"60b0654d380bf920","repo":"material-components/material-components-android","slug":"indicatortrackgapsize-must-be-0","errorCode":null,"errorMessage":"indicatorTrackGapSize must be >= 0.","messagePattern":"indicatorTrackGapSize must be >= 0\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java","lineNumber":294,"sourceCode":"  public int getTrackCornerRadiusInPx() {\n    return useRelativeTrackCornerRadius\n        ? (int) (trackThickness * trackCornerRadiusFraction)\n        : trackCornerRadius;\n  }\n\n  /**\n   * Returns true if the stroke ROUND cap should be used to prevent artifacts like (b/319309456),\n   * when fully rounded corners are specified.\n   */\n  public boolean useStrokeCap() {\n    return useRelativeTrackCornerRadius && trackCornerRadiusFraction == 0.5f;\n  }\n\n  @CallSuper\n  void validateSpec() {\n    if (indicatorTrackGapSize < 0) {\n      // Throws an exception if trying to use a negative gap size.\n      throw new IllegalArgumentException(\"indicatorTrackGapSize must be >= 0.\");\n    }\n  }\n}\n","sourceCodeStart":276,"sourceCodeEnd":298,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java#L276-L298","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"<!-- before -->\n<com.google.android.material.progressindicator.LinearProgressIndicator\n    app:indicatorTrackGapSize=\"-4dp\" ... />\n<!-- after -->\n<com.google.android.material.progressindicator.LinearProgressIndicator\n    app:indicatorTrackGapSize=\"4dp\" ... />","handlingStrategy":"validation","validationCode":"fun safeGapSize(desired: Int): Int = desired.coerceAtLeast(0)","typeGuard":null,"tryCatchPattern":"catch (e: IllegalArgumentException) { Log.e(TAG, \"Negative track gap; resetting to 0\", e); spec.indicatorTrackGapSize = 0 }","preventionTips":["Clamp computed gap dimensions to >= 0","Test layouts on small screens where subtraction can go negative","Keep dimension resources non-negative by convention"],"tags":["android","material-components","progressindicator","dimension","validation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}