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

  1. Verify the exact fully-qualified class name in configuration/code and that its artifact is a normal runtime dependency (not provided/optional)
  2. Ensure the class is reachable in native mode: annotate with @RegisterForReflection or add to reflection config if running -Dnative
  3. Call QuarkusClassloadingService.setClassLoader with the correct classloader if running outside the standard Quarkus TCCL context
  4. 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

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


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