bumptech/glide · error · IllegalStateException

Constructor for accepts too many parameters, it should…

Error message

Constructor for {} accepts too many parameters, it should accept no parameters, or a single Context

What it means

Thrown by Glide's annotation processor while generating the combined AppGlideModule. The processor inspects every constructor of your @GlideModule-annotated AppGlideModule subclass; a constructor with more than one parameter is unsupported. AppGlideModule may declare either a no-arg constructor or a single-arg constructor whose only parameter is android.content.Context (so the generated code can pass the application Context through). Anything else aborts code generation and fails the build.

Solutions

  1. Remove the extra constructor parameters so the AppGlideModule has either a no-arg constructor or a single android.content.Context parameter.
  2. If you need runtime dependencies, expose them through your Application/ApplicationComponent and resolve them inside registerComponents(...) or applyOptions(...), not via the constructor.
  3. If you genuinely need the Application/Context, keep exactly one parameter of type android.content.Context and obtain the Application from it inside the lifecycle methods.
  4. Delete any redundant hand-written constructors so the implicit/default no-arg constructor is used.

Example fix

// before
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
  private final HttpLoggingInterceptor logger;
  public MyAppGlideModule(Context context, HttpLoggingInterceptor logger) { ... }
}

// after
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
  // resolve dependencies inside registerComponents / applyOptions instead
  @Override
  public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
    HttpLoggingInterceptor logger = MyApp.get(context).logger();
    ...
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on code generation, assert the AppGlideModule shape at compile time in a test:
@Test void appGlideModuleHasValidConstructor() throws Exception {
  java.lang.reflect.Constructor<?>[] ctors = MyAppGlideModule.class.getDeclaredConstructors();
  for (java.lang.reflect.Constructor<?> c : ctors) {
    int n = c.getParameterCount();
    if (n == 0) continue;
    if (n == 1 && c.getParameterTypes()[0] == android.content.Context.class) continue;
    throw new AssertionError("AppGlideModule constructor must be no-arg or single Context: " + c);
  }
}

Prevention

When it happens

Trigger: AppModuleGenerator.doesAppGlideModuleConstructorAcceptContext(...) iterates appGlideModuleType.getEnclosedElements(); for an ElementKind.CONSTRUCTOR it reads constructor.getParameters() and throws when parameters.size() > 1. Triggered as soon as your AppGlideModule declares e.g. `public MyAppGlideModule(Application app, SomeDep dep)` or any 2+-arg constructor.

Common situations: Developers migrating a Glide v3 manifest-based module that took a Context plus extra dependencies; injecting a logger, config object, or feature flag into the AppGlideModule constructor; using DI (Dagger/Hilt) and trying to pass a component into the constructor instead of fields.

Related errors


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

Appendix: source

Thrown at annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleGenerator.java:253

          "new $T().registerComponents(context, glide, registry)", moduleClassName);
    }
    // Order matters here. The AppGlideModule must be called last.
    registerComponents.addStatement("appGlideModule.registerComponents(context, glide, registry)");
    return registerComponents.build();
  }

  private boolean doesAppGlideModuleConstructorAcceptContext(ClassName appGlideModule) {
    TypeElement appGlideModuleType =
        processingEnv.getElementUtils().getTypeElement(appGlideModule.reflectionName());

    for (Element enclosed : appGlideModuleType.getEnclosedElements()) {
      if (enclosed.getKind() == ElementKind.CONSTRUCTOR) {
        ExecutableElement constructor = (ExecutableElement) enclosed;
        List<? extends VariableElement> parameters = constructor.getParameters();
        if (parameters.isEmpty()) {
          return false;
        } else if (parameters.size() > 1) {
          throw new IllegalStateException(
              "Constructor for "
                  + appGlideModule
                  + " accepts too many parameters"
                  + ", it should accept no parameters, or a single Context");
        } else {
          VariableElement parameter = parameters.get(0);
          TypeMirror parameterType = parameter.asType();
          TypeMirror contextType =
              processingEnv.getElementUtils().getTypeElement("android.content.Context").asType();
          if (!processingEnv.getTypeUtils().isSameType(parameterType, contextType)) {
            throw new IllegalStateException("Unrecognized type: " + parameterType);
          }
          return true;
        }
      }
    }
    return false;
  }

View on GitHub (pinned to eb14a895d8)