bumptech/glide · error · IllegalArgumentException

@GlideOption methods should return a BaseRequestOptions<?> o

Error message

@GlideOption methods should return a BaseRequestOptions<?> object, but {} returns {}. If you're using old style @GlideOption 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

@GlideOption methods must return a BaseRequestOptions<?> (RequestOptions is the concrete subclass generated code chains on). Returning anything else — String, void (the deprecated old style), Integer, etc. — breaks the generated fluent API. validateGlideOption checks isBaseRequestOptions(returnType) and includes the actual return type plus the deprecated-void note in the message.

Source

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

          "RequestOptionsExtensions must be public, with private constructors and only static"
              + " methods. Found a non-private constructor in: "
              + getEnclosingClassName(element));
    }
    ExecutableElement executableElement = (ExecutableElement) element;
    if (!executableElement.getParameters().isEmpty()) {
      throw new IllegalArgumentException(
          "RequestOptionsExtensions must be public, with private constructors and only static"
              + " methods. Found parameters in the constructor of: "
              + getEnclosingClassName(element));
    }
  }

  private void validateGlideOption(ExecutableElement executableElement) {
    validateGlideOptionAnnotations(executableElement);
    validateGlideOptionParameters(executableElement);
    TypeMirror returnType = executableElement.getReturnType();
    if (!isBaseRequestOptions(returnType)) {
      throw new IllegalArgumentException(
          "@GlideOption methods should return a"
              + " BaseRequestOptions<?> object, but "
              + getQualifiedMethodName(executableElement)
              + " returns "
              + returnType
              + ". If you're using old style @GlideOption methods, your"
              + " method may have a void return type, but doing so is deprecated and support will"
              + " be removed in a future version");
    }
    validateGlideOptionOverride(executableElement);
  }

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

  private void validateGlideOptionParameters(ExecutableElement executableElement) {
    if (executableElement.getParameters().isEmpty()) {

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Change the @GlideOption method to return RequestOptions (or its generated GlideOptions) and end with `return options;`.
  2. Ensure the chain on `options` returns the same RequestOptions instance — `return options.centerCrop().placeholder(R.drawable.foo);`.
  3. If you intended the deprecated void style, be aware it is no longer supported in this version; migrate to the returning style.

Example fix

// before
@GlideOption
public static void cache(RequestOptions options) {
  options.diskCacheStrategy(DiskCacheStrategy.ALL);
}

// after
@GlideOption
public static RequestOptions cache(RequestOptions options) {
  return options.diskCacheStrategy(DiskCacheStrategy.ALL);
}
Defensive patterns

Strategy: type-guard

Type guard

// Compile-time type safety: declare the method signature to return RequestOptions.
// The Kotlin/Java compiler then guarantees a BaseRequestOptions<?> return.
@GlideOption
public static RequestOptions myOption(RequestOptions options) {
  return options.centerCrop(); // same type, no accidental void/foreign return
}

Prevention

When it happens

Trigger: GlideExtensionValidator.validateGlideOption reads executableElement.getReturnType(); if it is not assignable to com.bumptech.glide.request.BaseRequestOptions<?> (legacy string compare or erased-element compare per useLegacyTypeComparison), it throws. Hit by returning `void`, `String`, `Drawable`, or a custom type from a @GlideOption method.

Common situations: Porting old Glide v3 void-style options to the new API but forgetting to `return options`; chaining helpers that accidentally return a sub-result (`options.transform()` whose generic is fine, but returning a builder of a different type); returning `RequestBuilder` instead of `RequestOptions`.

Related errors


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