{"record":{"id":"7047531a536a5dcb","repo":"bumptech/glide","slug":"you-cannot-auto-lock-an-already-locked-options-obj","errorCode":null,"errorMessage":"You cannot auto lock an already locked options object, try clone() first","messagePattern":"You cannot auto lock an already locked options object, try clone\\(\\) first","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java","lineNumber":1303,"sourceCode":"  @SuppressWarnings(\"unchecked\")\n  public T lock() {\n    isLocked = true;\n    // This is the only place we should not check locked.\n    return self();\n  }\n\n  /**\n   * Similar to {@link #lock()} except that mutations cause a {@link #clone()} operation to happen\n   * before the mutation resulting in all methods returning a new Object and leaving the original\n   * locked object unmodified.\n   *\n   * <p>Auto clone is not retained by cloned objects returned from mutations. The cloned objects are\n   * mutable and are not locked.\n   */\n  @NonNull\n  public T autoClone() {\n    if (isLocked && !isAutoCloneEnabled) {\n      throw new IllegalStateException(\n          \"You cannot auto lock an already locked options object\" + \", try clone() first\");\n    }\n    isAutoCloneEnabled = true;\n    return lock();\n  }\n\n  @NonNull\n  @SuppressWarnings(\"unchecked\")\n  protected final T selfOrThrowIfLocked() {\n    if (isLocked) {\n      throw new IllegalStateException(\"You cannot modify locked T, consider clone()\");\n    }\n    return self();\n  }\n\n  protected final boolean isAutoCloneEnabled() {\n    return isAutoCloneEnabled;\n  }","sourceCodeStart":1285,"sourceCodeEnd":1321,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java#L1285-L1321","documentation":"Thrown by BaseRequestOptions.autoClone() when the options object is already locked (isLocked == true) but auto-clone has not yet been enabled. autoClone() turns a locked object into an auto-cloning one so that subsequent mutations transparently return clones, but you cannot retroactively flip this state on a plain-locked object because the caller may already hold a reference expecting immutability.","triggerScenarios":"Calling RequestOptions.lock() followed by RequestOptions.autoClone() on the same instance. lock() is applied internally by Glide when options are applied to a request (e.g. into()), so reusing the same RequestOptions builder across multiple loads and then calling autoClone() triggers it.","commonSituations":"Library/SDK authors building a shared RequestOptions singleton, calling apply() (which locks) and later autoClone(); calling autoClone() on options returned from Glide.init or from an already-built request.","solutions":["Call autoClone() on a fresh, unlocked clone: requestOptions.clone().autoClone()","Enable autoClone before the object ever gets locked (i.e. before it is applied to any request)","Avoid sharing a single mutable RequestOptions across many requests; build a new one per use or freeze a template and clone from it","Use RequestOptions.diskCacheStrategyOf(...) / factory-style helpers which return independent immutable instances"],"exampleFix":"// before\nval shared = RequestOptions().centerCrop()\nGlide.with(ctx).load(url).apply(shared).into(iv) // apply may lock shared\nshared.autoClone() // IllegalStateException\n\n// after\nval template = RequestOptions().centerCrop()\nval perRequest = template.clone().autoClone()\nGlide.with(ctx).load(url).apply(perRequest).into(iv)","handlingStrategy":"validation","validationCode":"fun RequestOptions.autoCloneSafe(): RequestOptions =\n  if (isLocked) clone().autoClone() else autoClone()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call autoClone() on a fresh unlocked instance, never on one already applied to a request","Treat RequestOptions stored in fields as immutable templates: always clone() before mutating","Avoid lock() then autoClone() on the same instance"],"tags":["android","glide","immutability","state-machine","request-options"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}