{"record":{"id":"a1e476f798103191","repo":"bumptech/glide","slug":"you-cannot-use-a-request-as-both-the-main-request","errorCode":null,"errorMessage":"You cannot use a request as both the main request and a thumbnail, consider using clone() on the request(s) passed to thumbnail()","messagePattern":"You cannot use a request as both the main request and a thumbnail, consider using clone\\(\\) on the request\\(s\\) passed to thumbnail\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/RequestBuilder.java","lineNumber":1255,"sourceCode":"    errorRequestCoordinator.setRequests(mainRequest, errorRequest);\n    return errorRequestCoordinator;\n  }\n\n  private Request buildThumbnailRequestRecursive(\n      Object requestLock,\n      Target<TranscodeType> target,\n      RequestListener<TranscodeType> targetListener,\n      @Nullable RequestCoordinator parentCoordinator,\n      TransitionOptions<?, ? super TranscodeType> transitionOptions,\n      Priority priority,\n      int overrideWidth,\n      int overrideHeight,\n      BaseRequestOptions<?> requestOptions,\n      Executor callbackExecutor) {\n    if (thumbnailBuilder != null) {\n      // Recursive case: contains a potentially recursive thumbnail request builder.\n      if (isThumbnailBuilt) {\n        throw new IllegalStateException(\n            \"You cannot use a request as both the main request and a \"\n                + \"thumbnail, consider using clone() on the request(s) passed to thumbnail()\");\n      }\n\n      TransitionOptions<?, ? super TranscodeType> thumbTransitionOptions =\n          thumbnailBuilder.transitionOptions;\n\n      // Apply our transition by default to thumbnail requests but avoid overriding custom options\n      // that may have been applied on the thumbnail request explicitly.\n      if (thumbnailBuilder.isDefaultTransitionOptionsSet) {\n        thumbTransitionOptions = transitionOptions;\n      }\n\n      Priority thumbPriority =\n          thumbnailBuilder.isPrioritySet()\n              ? thumbnailBuilder.getPriority()\n              : getThumbnailPriority(priority);\n","sourceCodeStart":1237,"sourceCodeEnd":1273,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/RequestBuilder.java#L1237-L1273","documentation":"When building a request that includes a thumbnail sub-request via thumbnail(RequestBuilder), Glide checks the isThumbnailBuilt flag to detect when the same RequestBuilder instance is used for both the main request and the thumbnail. This creates an infinite recursion because building the thumbnail triggers building the main request again. The IllegalStateException advises calling clone() so the thumbnail gets its own independent request builder.","triggerScenarios":"Calling requestBuilder.thumbnail(requestBuilder) using the same object for both. Assigning a RequestBuilder to a variable, using it for into(), and also passing it to thumbnail() on itself or a sibling that shares state.","commonSituations":"Building a request with a low-res thumbnail from the same URL: storing one RequestBuilder and passing it to both into and thumbnail. DRY-minded code that tries to reuse a single builder instance for multiple purposes.","solutions":["Call clone() on the builder before passing it to thumbnail(): builder.thumbnail(builder.clone())","Create two separate RequestBuilder instances: one for the main image and one for the thumbnail","For same-URL thumbnails, prefer the thumbnail(float) overload which does not have this problem"],"exampleFix":"// before\nRequestBuilder<Drawable> b = Glide.with(this).load(url);\nb.thumbnail(b).into(imageView);\n// after\nRequestBuilder<Drawable> b = Glide.with(this).load(url);\nb.thumbnail(b.clone()).into(imageView);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Always clone() the builder before passing it as a thumbnail\nRequestBuilder<Drawable> main = Glide.with(context).load(url);\nRequestBuilder<Drawable> thumb = main.clone(); // independent copy\nmain.thumbnail(thumb).into(imageView);","tryCatchPattern":null,"preventionTips":["Never pass the same RequestBuilder instance to both into() and thumbnail()","Call clone() on any builder before reusing it as a thumbnail","For same-URL thumbnails, prefer the thumbnail(float) overload to avoid this class of error"],"tags":["glide","thumbnail","request-builder","recursion"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}