bumptech/glide · error · IllegalStateException

Unrecognized type: {}

Error message

Unrecognized type: {}

What it means

Thrown by the same constructor scan as error 0, but only when your AppGlideModule has exactly one constructor parameter whose type is not android.content.Context. The processor supports only a single Context argument (anything else is ambiguous for code generation), so it refuses to generate the constructor call. The offending type name is appended to the message.

Source

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

    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;
  }

  private MethodSpec generateConstructor(
      ClassName appGlideModule,
      Collection<String> libraryGlideModuleClassNames,
      Collection<String> excludedGlideModuleClassNames) {
    MethodSpec.Builder constructorBuilder =
        MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addParameter(
                ParameterSpec.builder(ClassName.get("android.content", "Context"), "context")
                    .build());

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Change the single constructor parameter to exactly android.content.Context.
  2. If you currently take Application, switch to Context and cast to Application inside the body only if strictly required (`(Application) context.getApplicationContext()`).
  3. Prefer a no-arg constructor and obtain Context from the registerComponents/applyOptions callbacks that already receive it.

Example fix

// before
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
  public MyAppGlideModule(Application app) { ... }
}

// after
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
  public MyAppGlideModule(Context context) { ... }
  // or simply omit the constructor
}
Defensive patterns

Strategy: validation

Validate before calling

@Test void appGlideModuleSingleParamIsContext() throws Exception {
  for (java.lang.reflect.Constructor<?> c : MyAppGlideModule.class.getDeclaredConstructors()) {
    Class<?>[] p = c.getParameterTypes();
    if (p.length == 1 && p[0] != android.content.Context.class) {
      throw new AssertionError("Sole constructor param must be Context, got " + p[0]);
    }
  }
}

Prevention

When it happens

Trigger: AppModuleGenerator line 263: processingEnv.getTypeUtils().isSameType(parameterType, contextType) returns false for the sole parameter, where contextType is android.content.Context. Hit by e.g. `public MyAppGlideModule(Application app)` (Application is not the same type as Context) or `public MyAppGlideModule(String tag)`.

Common situations: Using android.app.Application (a Context subclass, but isSameType is strict equality, not assignability) as the constructor argument; passing a wrapper like ContextWrapper; passing a custom interface or a String tag.

Related errors


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