quarkusio/quarkus · error · RuntimeException

Unable to load context type: ${typeParam}

Error message

Unable to load context type: ${typeParam}

What it means

When scanning @ContextResolver classes, RESTEasy Reactive reads the ContextResolver's type parameter and attempts to load that context class with Class.forName at build time. If the class cannot be loaded from the thread context classloader, the scan fails with this RuntimeException.

Source

Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/scanning/ResteasyReactiveContextResolverScanner.java:65

        Collection<ClassInfo> resolvers = index
                .getAllKnownImplementors(ResteasyReactiveDotNames.CONTEXT_RESOLVER);
        for (ClassInfo resolverClass : resolvers) {
            ApplicationScanningResult.KeepProviderResult keepProviderResult = result
                    .keepProvider(resolverClass);
            if (keepProviderResult != ApplicationScanningResult.KeepProviderResult.DISCARD) {
                List<Type> typeParameters = JandexUtil.resolveTypeParameters(resolverClass.name(),
                        ResteasyReactiveDotNames.CONTEXT_RESOLVER,
                        index);
                DotName typeParam = typeParameters.get(0).name();
                ResourceContextResolver mapper = new ResourceContextResolver();
                mapper.setClassName(resolverClass.name().toString());
                mapper.setMediaTypeStrings(getProducesMediaTypes(resolverClass));
                try {
                    Class contextType = Class.forName(typeParam.toString(), false,
                            Thread.currentThread().getContextClassLoader());
                    contextResolvers.addContextResolver(contextType, mapper);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException("Unable to load context type: " + typeParam);
                }
            }
        }
        return contextResolvers;
    }

    private static List<String> getProducesMediaTypes(ClassInfo classInfo) {
        AnnotationInstance produces = classInfo.declaredAnnotation(ResteasyReactiveDotNames.PRODUCES);
        if (produces == null) {
            return Collections.emptyList();
        }
        return Arrays.asList(produces.value().asStringArray());
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Add the missing context type's artifact to the application's dependencies so the class is loadable.
  2. Make sure the resolver declares a concrete ContextResolver<MyContext> type parameter, not a raw type.
  3. Check for typos in the generic type name and that the class is in the same module/deployment as the resolver.
  4. Verify no packaging exclusions (e.g. Maven exclusions or native-mode removal) drop the class.

Example fix

// before
public class MyResolver implements ContextResolver { ... } // raw type
// after
public class MyResolver implements ContextResolver<MyContextClass> {
    public MyContextClass getContext(Class<?> type) { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

Class<?> ctxType;
try {
    ctxType = Class.forName(typeParam.toString(), false,
        Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
    throw new IllegalStateException("ContextResolver type " + typeParam + " not on classpath", e);
}

Type guard

boolean isResolvable(String className, ClassLoader cl) {
    try { cl.loadClass(className); return true; } catch (ClassNotFoundException e) { return false; }
}

Try / catch

try {
    scanner.scanForContextResolvers(...);
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Unable to load context type")) {
        log.error("Add the dependency containing the context type: " + e.getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: Implementing ContextResolver<T> where T resolves to a type that is not on the application classpath, or a raw/unresolvable parameterized type, so Class.forName(typeParam.toString()) throws ClassNotFoundException during scanning.

Common situations: A ContextResolver declared for a class from a dependency marked provided/optional and not packaged; typos in the generic type; use of a raw ContextResolver without a concrete type parameter; classloader differences in dev/test vs production.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1ba33008c22093cb. Report an issue: GitHub.