{"record":{"id":"8f15fb5ac82d7890","repo":"bumptech/glide","slug":"multiplier-must-be-0","errorCode":null,"errorMessage":"Multiplier must be >= 0","messagePattern":"Multiplier must be >= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/util/LruCache.java","lineNumber":43,"sourceCode":"   *\n   * @param size The maximum size of the cache, the units must match the units used in {@link\n   *     #getSize(Object)}.\n   */\n  public LruCache(long size) {\n    this.initialMaxSize = size;\n    this.maxSize = size;\n  }\n\n  /**\n   * Sets a size multiplier that will be applied to the size provided in the constructor to put the\n   * new size of the cache. If the new size is less than the current size, entries will be evicted\n   * until the current size is less than or equal to the new size.\n   *\n   * @param multiplier The multiplier to apply.\n   */\n  public synchronized void setSizeMultiplier(float multiplier) {\n    if (multiplier < 0) {\n      throw new IllegalArgumentException(\"Multiplier must be >= 0\");\n    }\n    maxSize = Math.round(initialMaxSize * multiplier);\n    evict();\n  }\n\n  /**\n   * Returns the size of a given item, defaulting to one. The units must match those used in the\n   * size passed in to the constructor. Subclasses can override this method to return sizes in\n   * various units, usually bytes.\n   *\n   * @param item The item to get the size of.\n   */\n  protected int getSize(@Nullable Y item) {\n    return 1;\n  }\n\n  /** Returns the number of entries stored in cache. */\n  protected synchronized int getCount() {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/util/LruCache.java#L25-L61","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Clamp the multiplier to >= 0 (and typically <= 1) before calling: multiplier.coerceAtLeast(0f)","Use the documented MemoryCategory values (HIGH=1, NORMAL=1, LOW=0.5) via Glide.setMemoryCategory rather than raw floats","Guard the computation: multiplier = if (availableMb < 0) 0f else availableMb / totalMb","Add a unit test that asserts the multiplier is non-negative for all input states"],"exampleFix":"// before\nval mult = (freeBytes - reserved) / totalBytes.toFloat() // can be negative\nlruCache.setSizeMultiplier(mult)\n\n// after\nval mult = ((freeBytes - reserved) / totalBytes.toFloat()).coerceIn(0f, 1f)\nlruCache.setSizeMultiplier(mult)","handlingStrategy":"validation","validationCode":"fun safeMultiplier(value: Float): Float = value.coerceAtLeast(0f)\nlruCache.setSizeMultiplier(safeMultiplier(raw))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp multipliers to >= 0 (and usually <= 1) before calling setSizeMultiplier","Use Glide.setMemoryCategory(MemoryCategory.LOW/NORMAL/HIGH) rather than raw floats","Unit-test trim-memory logic with edge inputs (negative available memory)"],"tags":["android","glide","cache","validation","range-check"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}