bumptech/glide · error · IllegalArgumentException

@GlideType methods should return a RequestBuilder<{}> object

Error message

@GlideType methods should return a RequestBuilder<{}> object, but {} returns: {}. If you're using old style @GlideType methods, your method may have a void return type, but doing so is deprecated and support will be removed in a future version

What it means

@GlideType methods add RequestManager entry points (e.g. `GlideApp.asGif()`). They must return RequestBuilder<T> where T equals the Class<?> in the annotation's `value()`. validateGlideType checks both isRequestBuilder(returnType) and typeMatchesExpected(returnType, executableElement); failing either throws with the expected class and the actual return type.

Source

Thrown at annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java:228

      }
    }
    return true;
  }

  private static List<TypeMirror> getComparableParameterTypes(
      ExecutableElement element, boolean skipFirst) {
    return element.getParameters().stream()
        .skip(skipFirst ? 1 : 0)
        .map(VariableElement::asType)
        .toList();
  }

  private void validateGlideType(ExecutableElement executableElement) {
    TypeMirror returnType = executableElement.getReturnType();
    validateGlideTypeAnnotations(executableElement);
    if (!isRequestBuilder(returnType) || !typeMatchesExpected(returnType, executableElement)) {
      String expectedClassName = getGlideTypeValue(executableElement);
      throw new IllegalArgumentException(
          "@GlideType methods should return a RequestBuilder<"
              + expectedClassName
              + "> object, but "
              + getQualifiedMethodName(executableElement)
              + " returns: "
              + returnType
              + ". If you're using old style @GlideType methods, your"
              + " method may have a void return type, but doing so is deprecated and support will"
              + " be removed in a future version");
    }
    validateGlideTypeParameters(executableElement);
  }

  private String getGlideTypeValue(ExecutableElement executableElement) {
    return processorUtil
        .findClassValuesFromAnnotationOnClassAsNames(executableElement, GlideType.class)
        .iterator()
        .next();

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Match the return type exactly to the annotation: `@GlideType(GifDrawable.class) public static RequestBuilder<GifDrawable> asGif(RequestBuilder<GifDrawable> requestBuilder) { ... }`.
  2. Ensure the generic parameter of the returned RequestBuilder equals `value()`.
  3. Migrate any deprecated void-style @GlideType method to the returning style.

Example fix

// before
@GlideType(GifDrawable.class)
public static RequestBuilder<Bitmap> asGif(RequestBuilder<GifDrawable> requestBuilder) {
  return requestBuilder;
}

// after
@GlideType(GifDrawable.class)
public static RequestBuilder<GifDrawable> asGif(RequestBuilder<GifDrawable> requestBuilder) {
  return requestBuilder;
}
Defensive patterns

Strategy: type-guard

Type guard

// Let the compiler enforce the return/param type match via generics.
@GlideType(com.bumptech.glide.load.resource.gif.GifDrawable.class)
public static com.bumptech.glide.RequestBuilder<com.bumptech.glide.load.resource.gif.GifDrawable>
    asGif(com.bumptech.glide.RequestBuilder<com.bumptech.glide.load.resource.gif.GifDrawable> requestBuilder) {
  return requestBuilder;
}

Prevention

When it happens

Trigger: GlideExtensionValidator.validateGlideType reads `returnType = executableElement.getReturnType()` and `expectedClassName = getGlideTypeValue(executableElement)`; throws when `!isRequestBuilder(returnType) || !typeMatchesExpected(returnType, executableElement)`. Hit by returning void, RequestOptions, Drawable, or a RequestBuilder whose generic does not match `value()` (e.g. `@GlideType(GifDrawable.class)` returning `RequestBuilder<Bitmap>`).

Common situations: Mismatch between the `value()` class and the RequestBuilder generic; using the deprecated void style; returning the bare RequestBuilder without a type parameter; copy-pasting a @GlideType method and forgetting to update `value()`.

Related errors


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