bumptech/glide · error · IllegalArgumentException

Multiplier must be >= 0

Error message

Multiplier must be >= 0

What it means

Thrown by LruCache.setSizeMultiplier(float) when the supplied multiplier is negative. The multiplier scales the cache's maximum size relative to its initial maxSize, and a negative value would compute a negative max size, which the eviction logic cannot handle. Note 0 is allowed (empties the cache).

Source

Thrown at library/src/main/java/com/bumptech/glide/util/LruCache.java:43

   *
   * @param size The maximum size of the cache, the units must match the units used in {@link
   *     #getSize(Object)}.
   */
  public LruCache(long size) {
    this.initialMaxSize = size;
    this.maxSize = size;
  }

  /**
   * Sets a size multiplier that will be applied to the size provided in the constructor to put the
   * new size of the cache. If the new size is less than the current size, entries will be evicted
   * until the current size is less than or equal to the new size.
   *
   * @param multiplier The multiplier to apply.
   */
  public synchronized void setSizeMultiplier(float multiplier) {
    if (multiplier < 0) {
      throw new IllegalArgumentException("Multiplier must be >= 0");
    }
    maxSize = Math.round(initialMaxSize * multiplier);
    evict();
  }

  /**
   * Returns the size of a given item, defaulting to one. The units must match those used in the
   * size passed in to the constructor. Subclasses can override this method to return sizes in
   * various units, usually bytes.
   *
   * @param item The item to get the size of.
   */
  protected int getSize(@Nullable Y item) {
    return 1;
  }

  /** Returns the number of entries stored in cache. */
  protected synchronized int getCount() {

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Clamp the multiplier to >= 0 (and typically <= 1) before calling: multiplier.coerceAtLeast(0f)
  2. Use the documented MemoryCategory values (HIGH=1, NORMAL=1, LOW=0.5) via Glide.setMemoryCategory rather than raw floats
  3. Guard the computation: multiplier = if (availableMb < 0) 0f else availableMb / totalMb
  4. Add a unit test that asserts the multiplier is non-negative for all input states

Example fix

// before
val mult = (freeBytes - reserved) / totalBytes.toFloat() // can be negative
lruCache.setSizeMultiplier(mult)

// after
val mult = ((freeBytes - reserved) / totalBytes.toFloat()).coerceIn(0f, 1f)
lruCache.setSizeMultiplier(mult)
Defensive patterns

Strategy: validation

Validate before calling

fun safeMultiplier(value: Float): Float = value.coerceAtLeast(0f)
lruCache.setSizeMultiplier(safeMultiplier(raw))

Prevention

When it happens

Trigger: Calling Glide.get(context).setMemoryCategory(...) (which internally calls BitmapPool/LruCache setSizeMultiplier) with a negative value; directly calling LruCache.setSizeMultiplier on a custom cache with a negative number; computing a multiplier from a metric that can go negative.

Common situations: Trim-memory logic that derives a multiplier from available memory and underflows to negative; passing a MemoryCategory with a custom low bound below LOW; misreading the API and passing a percentage without normalization.

Related errors


AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14). Data as JSON: /api/errors/8f15fb5ac82d7890. Report an issue: GitHub.