bumptech/glide · error · IllegalArgumentException

@GlideType methods must take a RequestBuilder object as thei

Error message

@GlideType methods must take a RequestBuilder object as their first and only parameter, but given: {} for: {}

What it means

The single parameter of a @GlideType method must be a RequestBuilder (matching the annotation's `value()` type). validateGlideTypeParameters reads the first parameter's type and throws when it is not a RequestBuilder — legacy path compares by `toString().startsWith("com.bumptech.glide.RequestBuilder")`, modern path uses erased-element equality against com.bumptech.glide.RequestBuilder.

Source

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

    TypeMirror toCompare = types.erasure(typeMirror);
    return Objects.equals(
        types.asElement(toCompare), elements.getTypeElement("com.bumptech.glide.RequestBuilder"));
  }

  private void validateGlideTypeParameters(ExecutableElement executableElement) {
    if (executableElement.getParameters().size() != 1) {
      throw new IllegalArgumentException(
          "@GlideType methods must take a"
              + " RequestBuilder object as their first and only parameter, but given multiple for: "
              + getQualifiedMethodName(executableElement));
    }

    VariableElement first = executableElement.getParameters().get(0);
    TypeMirror argumentType = first.asType();
    if (useLegacyTypeComparison
        ? !argumentType.toString().startsWith("com.bumptech.glide.RequestBuilder")
        : !isRequestBuilder(argumentType)) {
      throw new IllegalArgumentException(
          "@GlideType methods must take a"
              + " RequestBuilder object as their first and only parameter, but given: "
              + argumentType
              + " for: "
              + getQualifiedMethodName(executableElement));
    }
  }

  private void validateGlideTypeAnnotations(ExecutableElement executableElement) {
    validateAnnotatedNonNull(executableElement);
  }

  private void validateAnnotatedNonNull(ExecutableElement executableElement) {
    Set<String> annotationNames =
        FluentIterable.from(executableElement.getAnnotationMirrors())
            .transform(
                new Function<AnnotationMirror, String>() {
                  @Override

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Declare the single parameter as `RequestBuilder<T>` where T matches `@GlideType(T.class)`.
  2. If you intended to customize RequestOptions, move the method to be a @GlideOption instead and change the parameter to RequestOptions.

Example fix

// before
@GlideType(GifDrawable.class)
public static RequestBuilder<GifDrawable> asGif(RequestOptions options) {
  ...
}

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

Strategy: validation

Validate before calling

@Test void glideTypeParamIsRequestBuilder() throws Exception {
  for (java.lang.reflect.Method m : MyGlideExtension.class.getDeclaredMethods()) {
    if (m.isAnnotationPresent(com.bumptech.glide.annotation.GlideType.class)) {
      Class<?> first = m.getParameterTypes()[0];
      assertTrue("@GlideType param must be RequestBuilder: " + m + " got " + first,
          com.bumptech.glide.RequestBuilder.class.isAssignableFrom(first));
    }
  }
}

Prevention

When it happens

Trigger: GlideExtensionValidator.validateGlideTypeParameters: after the size==1 check, `if (useLegacyTypeComparison ? !argumentType.toString().startsWith("com.bumptech.glide.RequestBuilder") : !isRequestBuilder(argumentType)) throw`. Hit by passing a RequestOptions, Drawable, or any non-RequestBuilder as the sole parameter.

Common situations: Confusing @GlideType (operates on RequestBuilder) with @GlideOption (operates on RequestOptions); passing a raw `RequestBuilder` without the generic; using a custom RequestBuilder subclass not recognized due to legacy comparison.

Related errors


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