bumptech/glide · error · IllegalArgumentException

@GlideOption methods must take a BaseRequestOptions<?> objec

Error message

@GlideOption methods must take a BaseRequestOptions<?> object as their first parameter, but the first parameter in {} is {}

What it means

The first parameter of a @GlideOption method must be a BaseRequestOptions<?> (so the generated code can pass through the RequestOptions being customized). validateGlideOptionParameters checks isBaseRequestOptions(expected) on the first parameter's type and rejects anything else (e.g. Context, String, Drawable), printing both the method and the offending type.

Source

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

    validateGlideOptionOverride(executableElement);
  }

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

  private void validateGlideOptionParameters(ExecutableElement executableElement) {
    if (executableElement.getParameters().isEmpty()) {
      throw new IllegalArgumentException(
          "@GlideOption methods must take a "
              + "BaseRequestOptions<?> object as their first parameter, but "
              + getQualifiedMethodName(executableElement)
              + " has none");
    }
    VariableElement first = executableElement.getParameters().get(0);
    TypeMirror expected = first.asType();
    if (!isBaseRequestOptions(expected)) {
      throw new IllegalArgumentException(
          "@GlideOption methods must take a"
              + " BaseRequestOptions<?> object as their first parameter, but the first parameter"
              + " in "
              + getQualifiedMethodName(executableElement)
              + " is "
              + expected);
    }
  }

  private boolean isBaseRequestOptions(TypeMirror typeMirror) {
    if (useLegacyTypeComparison) {
      return typeMirror.toString().equals("com.bumptech.glide.request.BaseRequestOptions<?>");
    }
    return typeMirror instanceof DeclaredType declaredType
        && declaredType.asElement() instanceof TypeElement typeElement
        && typeElement
            .getQualifiedName()
            .contentEquals("com.bumptech.glide.request.BaseRequestOptions");

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Make the first parameter `RequestOptions options` (or the generated RequestOptions subclass) — the object the method extends.
  2. Move any extra inputs (resource ids, Drawables) to subsequent parameters after the RequestOptions one.
  3. If using a custom RequestOptions subclass, confirm the processor's BaseRequestOptions comparison recognizes it (prefer the standard RequestOptions).

Example fix

// before
@GlideOption
public static RequestOptions avatar(RequestBuilder<?> builder, int placeholder) {
  return builder.placeholder(placeholder);
}

// after
@GlideOption
public static RequestOptions avatar(RequestOptions options, int placeholder) {
  return options.placeholder(placeholder);
}
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: GlideExtensionValidator.validateGlideOptionParameters reads the first VariableElement, takes its asType(), and if it is not BaseRequestOptions<?> throws. Hit by methods whose first parameter is e.g. `Context`, `int`, `Drawable`, or `RequestBuilder` (wrong base type).

Common situations: Mistakenly taking a RequestBuilder (that belongs to @GlideType) as the first parameter; passing a resource id or Drawable as the first parameter instead of RequestOptions; using a custom subclass not recognized as BaseRequestOptions due to legacy type comparison.

Related errors


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