quarkusio/quarkus · error · java.lang.RuntimeException
Cannot invoke constructor: ${className}
Error message
Cannot invoke constructor: ${className} What it means
ArC's Reflections.newInstance() uses reflection to instantiate a bean class via its constructor. This RuntimeException wraps reflective failures (InstantiationException, IllegalAccessException, IllegalArgumentException) that occur while invoking the resolved constructor, e.g. the class is abstract, has no accessible constructor, or the arguments do not match. The message includes the class name whose constructor could not be invoked.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Reflections.java:145
Constructor<?> constructor = findConstructor(clazz, parameterTypes);
if (constructor != null) {
if (!constructor.canAccess(null)) {
constructor.setAccessible(true);
}
try {
return constructor.newInstance(args);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
// this method is only used to instantiate beans, so throwing `CreationException` is fine
throw new CreationException(cause);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException("Cannot invoke constructor: " + clazz.getName(), e);
}
}
throw new RuntimeException(
"No " + clazz.getName() + "constructor found for params: " + Arrays.toString(parameterTypes));
}
public static Object readField(Class<?> clazz, String name, Object instance) {
try {
Field field = clazz.getDeclaredField(name);
if (!field.canAccess(instance)) {
field.setAccessible(true);
}
return field.get(instance);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Cannot read field value: " + clazz.getName() + "#" + name, e);
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Check that the class is concrete, public, and has a matching constructor for the given parameter types
- Verify argument types exactly match the resolved constructor parameters ( boxing/primitives matter)
- Ensure the class is not a non-static inner class or interface/abstract type
- Inspect the chained cause 'e' in the stack trace for the underlying reflective failure
Example fix
// before Object o = Reflections.newInstance(MyAbstractBean.class, new Class<?>[0], new Object[0]); // after Object o = Reflections.newInstance(MyConcreteBean.class, new Class<?>[0], new Object[0]);
Defensive patterns
Strategy: validation
Validate before calling
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()))
throw new IllegalArgumentException(clazz + " must be concrete");
if (clazz.getDeclaredConstructors().length == 0)
throw new IllegalArgumentException(clazz + " has no declared constructor"); Type guard
static boolean isInstantiable(Class<?> c) { return !c.isInterface() && !Modifier.isAbstract(c.getModifiers()) && !c.isMemberClass(); } Try / catch
try { return Reflections.newInstance(clazz, types, args); }
catch (RuntimeException e) { log.error("Bean instantiation failed for " + clazz, e); throw e; } Prevention
- Use concrete public classes for beans
- Match constructor parameter types exactly, including primitives vs boxed types
- Avoid non-static inner classes as beans
When it happens
Trigger: Calling Reflections.newInstance(clazz, parameterTypes, args) where the constructor throws InstantiationException (abstract/interface class), access is denied (non-public class/constructor under strict access checks), or an IllegalArgumentException occurs (argument type mismatch or null for a primitive parameter).
Common situations: Registering a synthetic bean or extension that points at an abstract class; a proxy/superclass whose constructor is inaccessible after packaging; passing arguments whose types don't exactly match the resolved constructor parameters; instantiating a nested non-static class.
Related errors
- No ${className}constructor found for params: ${parameterType
- Cannot read field value: ${className}#${name}
- Cannot set field value: ${className}#${name}
- Not an array type ${type}
- Unsupported injection point target: <injectionPoint>
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/35415ca560df24c0.
Report an issue: GitHub.