material-components/material-components-android · error · IllegalArgumentException

endIconSize cannot be less than 0

Error message

endIconSize cannot be less than 0

What it means

EndCompoundLayout.setEndIconMinSize validates that the minimum end-icon size is non-negative and applies it to the end icon and error icon views. A negative size has no valid meaning for view sizing, so it throws IllegalArgumentException immediately.

Source

Thrown at lib/java/com/google/android/material/textfield/EndCompoundLayout.java:577

  }

  void setEndIconTintList(@Nullable ColorStateList endIconTintList) {
    if (this.endIconTintList != endIconTintList) {
      this.endIconTintList = endIconTintList;
      applyIconTint(textInputLayout, endIconView, this.endIconTintList, endIconTintMode);
    }
  }

  void setEndIconTintMode(@Nullable PorterDuff.Mode endIconTintMode) {
    if (this.endIconTintMode != endIconTintMode) {
      this.endIconTintMode = endIconTintMode;
      applyIconTint(textInputLayout, endIconView, endIconTintList, this.endIconTintMode);
    }
  }

  void setEndIconMinSize(@Px int iconSize) {
    if (iconSize < 0) {
      throw new IllegalArgumentException("endIconSize cannot be less than 0");
    }
    if (iconSize != endIconMinSize) {
      endIconMinSize = iconSize;
      setIconMinSize(endIconView, iconSize);
      setIconMinSize(errorIconView, iconSize);
    }
  }

  int getEndIconMinSize() {
    return endIconMinSize;
  }

  void setEndIconScaleType(@NonNull ScaleType endIconScaleType) {
    this.endIconScaleType = endIconScaleType;
    setIconScaleType(endIconView, endIconScaleType);
    setIconScaleType(errorIconView, endIconScaleType);
  }

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Pass a non-negative dimension: setEndIconMinSize(getResources().getDimensionPixelSize(R.dimen.icon_min)).
  2. Treat -1/UNSPECIFIED sentinels as 'do not set' instead of forwarding them to the API.
  3. Check app:endIconMinSize values in XML are positive dimensions.

Example fix

// before
int size = prefs.getInt("icon_min", -1);
til.setEndIconMinSize(size); // -1 throws

// after
int size = prefs.getInt("icon_min", 0);
if (size >= 0) til.setEndIconMinSize(size);
Defensive patterns

Strategy: validation

Validate before calling

if (iconMinSize >= 0) til.setEndIconMinSize(iconMinSize);

Prevention

When it happens

Trigger: Calling textInputLayout.setEndIconMinSize(negative) in code, or passing a negative dimension for app:endIconMinSize in XML.

Common situations: Computing icon size from a resource/variable that can be -1 (e.g. an unresolved dimension or an unselected sentinel); typos in dimens; mirroring an attribute value between start/end icons with a sign error.

Related errors


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