{"record":{"id":"d10187456f4b1ead","repo":"bumptech/glide","slug":"constructor-for-accepts-too-many-parameters-it","errorCode":null,"errorMessage":"Constructor for {} accepts too many parameters, it should accept no parameters, or a single Context","messagePattern":"Constructor for (.+?) accepts too many parameters, it should accept no parameters, or a single Context","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleGenerator.java","lineNumber":253,"sourceCode":"          \"new $T().registerComponents(context, glide, registry)\", moduleClassName);\n    }\n    // Order matters here. The AppGlideModule must be called last.\n    registerComponents.addStatement(\"appGlideModule.registerComponents(context, glide, registry)\");\n    return registerComponents.build();\n  }\n\n  private boolean doesAppGlideModuleConstructorAcceptContext(ClassName appGlideModule) {\n    TypeElement appGlideModuleType =\n        processingEnv.getElementUtils().getTypeElement(appGlideModule.reflectionName());\n\n    for (Element enclosed : appGlideModuleType.getEnclosedElements()) {\n      if (enclosed.getKind() == ElementKind.CONSTRUCTOR) {\n        ExecutableElement constructor = (ExecutableElement) enclosed;\n        List<? extends VariableElement> parameters = constructor.getParameters();\n        if (parameters.isEmpty()) {\n          return false;\n        } else if (parameters.size() > 1) {\n          throw new IllegalStateException(\n              \"Constructor for \"\n                  + appGlideModule\n                  + \" accepts too many parameters\"\n                  + \", it should accept no parameters, or a single Context\");\n        } else {\n          VariableElement parameter = parameters.get(0);\n          TypeMirror parameterType = parameter.asType();\n          TypeMirror contextType =\n              processingEnv.getElementUtils().getTypeElement(\"android.content.Context\").asType();\n          if (!processingEnv.getTypeUtils().isSameType(parameterType, contextType)) {\n            throw new IllegalStateException(\"Unrecognized type: \" + parameterType);\n          }\n          return true;\n        }\n      }\n    }\n    return false;\n  }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleGenerator.java#L235-L271","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the extra constructor parameters so the AppGlideModule has either a no-arg constructor or a single android.content.Context parameter.","If you need runtime dependencies, expose them through your Application/ApplicationComponent and resolve them inside registerComponents(...) or applyOptions(...), not via the constructor.","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.","Delete any redundant hand-written constructors so the implicit/default no-arg constructor is used."],"exampleFix":"// before\n@GlideModule\npublic class MyAppGlideModule extends AppGlideModule {\n  private final HttpLoggingInterceptor logger;\n  public MyAppGlideModule(Context context, HttpLoggingInterceptor logger) { ... }\n}\n\n// after\n@GlideModule\npublic class MyAppGlideModule extends AppGlideModule {\n  // resolve dependencies inside registerComponents / applyOptions instead\n  @Override\n  public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {\n    HttpLoggingInterceptor logger = MyApp.get(context).logger();\n    ...\n  }\n}","handlingStrategy":"validation","validationCode":"// Before relying on code generation, assert the AppGlideModule shape at compile time in a test:\n@Test void appGlideModuleHasValidConstructor() throws Exception {\n  java.lang.reflect.Constructor<?>[] ctors = MyAppGlideModule.class.getDeclaredConstructors();\n  for (java.lang.reflect.Constructor<?> c : ctors) {\n    int n = c.getParameterCount();\n    if (n == 0) continue;\n    if (n == 1 && c.getParameterTypes()[0] == android.content.Context.class) continue;\n    throw new AssertionError(\"AppGlideModule constructor must be no-arg or single Context: \" + c);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep AppGlideModule constructors to no-arg or a single android.content.Context.","Resolve dependencies inside registerComponents/applyOptions (which already receive Context), never via the constructor.","Avoid passing Application or wrapper types — the processor uses strict type equality, not assignability."],"tags":["glide","annotation-processing","appglidemodule","constructor"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}