quarkusio/quarkus · error · IllegalArgumentException
Class '%s' which is used as %s in class '%s' must have a no-
Error message
Class '%s' which is used as %s in class '%s' must have a no-args constructor
What it means
List-of-object YAML config binding instantiates each element via its no-arg constructor. If the element class lacks a no-args constructor, Quarkus cannot create instances and deployment fails with IllegalArgumentException.
Source
Thrown at extensions/spring-boot-properties/deployment/src/main/java/io/quarkus/spring/boot/properties/deployment/YamlListObjectHandler.java:206
b.invokeVirtual(
MethodDesc.of(HashMap.class, "put", Object.class, Object.class, Object.class),
resultHandle, Const.of(entry.getKey()), Const.of(entry.getValue()));
}
b.return_(resultHandle);
});
});
}
});
}
private void validateClass(ClassInfo classInfo, Member member) {
if (Modifier.isInterface(classInfo.flags())) {
throw new IllegalArgumentException(
"The use of interfaces as the generic type of Lists fields / methods is not allowed. Offending field is '"
+ member.name() + "' of class '" + member.declaringClass().name().toString() + "'");
}
if (!classInfo.hasNoArgsConstructor()) {
throw new IllegalArgumentException(
String.format("Class '%s' which is used as %s in class '%s' must have a no-args constructor", classInfo,
member.phraseUsage(), member.declaringClass().name().toString()));
}
if (!Modifier.isPublic(classInfo.flags())) {
throw new IllegalArgumentException(
String.format("Class '%s' which is used as %s in class '%s' must be a public class", classInfo,
member.phraseUsage(), member.declaringClass().name().toString()));
}
}
private ClassInfo validateType(Type type) {
if (type.kind() != Type.Kind.PARAMETERIZED_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARGUMENT_MESSAGE);
}
ParameterizedType parameterizedType = (ParameterizedType) type;
if (!DotNames.LIST.equals(parameterizedType.name())) {
throw new IllegalArgumentException(ILLEGAL_ARGUMENT_MESSAGE);
}View on GitHub (pinned to e1c734241f)
Solutions
- Add a public no-args constructor to the element class
- Use Lombok @NoArgsConstructor alongside the other constructors
- Switch to standard Quarkus @ConfigMapping interface binding, which does not require a no-args constructor
Example fix
// before
public class ServerConfig { private final String host; public ServerConfig(String host){...} }
// after
public class ServerConfig { public ServerConfig(){} public ServerConfig(String host){...} } Defensive patterns
Strategy: validation
Validate before calling
static void requireNoArgsConstructor(Class<?> c) {
try { c.getDeclaredConstructor(); }
catch (NoSuchMethodException e) { throw new IllegalStateException(c + " needs a public no-args constructor for YAML config binding"); }
} Type guard
boolean isInstantiableForConfig(Class<?> c) {
try { c.getDeclaredConstructor(); return java.lang.reflect.Modifier.isPublic(c.getModifiers()); }
catch (NoSuchMethodException e) { return false; }
} Try / catch
catch (IllegalArgumentException e) { if (e.getMessage().contains("no-args constructor")) { /* add no-args ctor */ } throw e; } Prevention
- Always give config POJOs a public no-args constructor
- Pair Lombok @AllArgsConstructor with @NoArgsConstructor
- Prefer @ConfigMapping interfaces which avoid instantiation requirements
When it happens
Trigger: A List<SomeClass> config member whose SomeClass has only constructors with parameters (e.g. required-args or builder-only style) processed by YamlListObjectHandler.
Common situations: Immutable config objects with constructor initialization, records-like patterns, or classes generated by Lombok @AllArgsConstructor without @NoArgsConstructor.
Related errors
- Support for List of objects in classes annotated with '@Conf
- The use of interfaces as the generic type of Lists fields /
- Class '%s' which is used as %s in class '%s' must be a publi
- YamlListObjectHandler can only be used for fields / methods
- Unable to serialize ${param} as the wrong number of paramete
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/7994c235ddc5dd9a.
Report an issue: GitHub.