quarkusio/quarkus · error · RuntimeException
Can not load class []
Error message
Can not load class []
What it means
QuarkusClassloadingService.loadClass resolves class names by string (used by SmallRye GraphQL for data fetchers/token providers) via the configured or TCCL classloader and wraps any ClassNotFoundException into RuntimeException 'Can not load class [<className>]'. The empty brackets in the logged message indicate the className string failed to resolve at runtime.
Source
Thrown at extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/spi/QuarkusClassloadingService.java:41
*/
private static volatile ClassLoader classLoader;
@Override
public String getName() {
return "Quarkus";
}
@Override
public Class<?> loadClass(String className) {
try {
if (Classes.isPrimitive(className)) {
return Classes.getPrimativeClassType(className);
} else {
ClassLoader cl = classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader;
return loadClass(className, cl);
}
} catch (ClassNotFoundException pae) {
throw new RuntimeException("Can not load class [" + className + "]", pae);
}
}
public static void setClassLoader(ClassLoader classLoader) {
QuarkusClassloadingService.classLoader = classLoader;
PropertyDataFetcherHelper.clearReflectionCache();
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Verify the exact fully-qualified class name in configuration/code and that its artifact is a normal runtime dependency (not provided/optional)
- Ensure the class is reachable in native mode: annotate with @RegisterForReflection or add to reflection config if running -Dnative
- Call QuarkusClassloadingService.setClassLoader with the correct classloader if running outside the standard Quarkus TCCL context
- Check the runtime classpath (mvn dependency:tree / native image config) for the jar containing the class
Example fix
// before quarkus.smallrye-graphql.authorization-token-propagation.enabled=true # class name typo / missing dependency -> Can not load class [com.example.MyProvider] // after (pom.xml) <dependency> <groupId>com.example</groupId> <artifactId>my-providers</artifactId> </dependency>
Defensive patterns
Strategy: try-catch
Validate before calling
// Verify the class is loadable before handing its name to GraphQL runtime config
try {
Class.forName("com.example.MyTokenProvider", false,
Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Token provider class missing from runtime classpath", e);
} Type guard
function isClassLoadError(e) {
return e instanceof Error && /^Can not load class \[/.test(e.message);
} Try / catch
try {
Class<?> provider = QuarkusClassloadingService.loadClass("com.example.MyTokenProvider");
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Can not load class [")) {
throw new IllegalStateException("Add the artifact containing " + e.getMessage() + " to runtime deps", e);
}
throw e;
} Prevention
- Double-check FQCNs in configuration; never mark provider classes 'provided' or 'optional' if used at runtime
- Annotate reflectively loaded classes with @RegisterForReflection for native builds
- Call setClassLoader explicitly when running outside standard Quarkus context
- Verify with mvn dependency:tree that the class's artifact reaches the runtime module
When it happens
Trigger: A configured or reflectively referenced class name (e.g. a token provider class in quarkus.smallrye-graphql.* config or property-based wiring) is not on the runtime application classpath — misspelled FQCN, class in a provided/optional dependency not packaged, or native-mode class not registered.
Common situations: Typos in class names in application.properties; depending on a class from a library marked <scope>provided</scope>; GraalVM native image where the class was eliminated without @RegisterForReflection; hot-reload windows where the classloader was swapped.
Related errors
- Failed to load the condition class ${testClassName} for capa
- The class (${name}) cannot be created during deployment.
- Unable to load repository/entity class mapping ->
- Unable to load class '{className}' for supporting custom JSO
- Unable load class '''
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/3c8e0f33ad2da76a.
Report an issue: GitHub.