quarkusio/quarkus · error · ConstraintViolationException
(dynamic: constructor parameter constraint violations summar
Error message
(dynamic: constructor parameter constraint violations summary)
What it means
Thrown by the method-validation interceptor when constructor parameters violate Bean Validation constraints. ExecutableValidator.validateConstructorParameters runs before the constructor body executes; any violation results in a ConstraintViolationException carrying a summary listing the constructor, argument values, and each violation, so the object is never created.
Source
Thrown at extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/interceptor/AbstractMethodValidationInterceptor.java:102
/**
* Validates the Bean Validation constraints specified at the parameters and/or
* return value of the intercepted constructor.
*
* @param ctx The context of the intercepted constructor invocation.
*
* @throws Exception Any exception caused by the intercepted constructor
* invocation. A {@link ConstraintViolationException} in case
* at least one constraint violation occurred either during
* parameter or return value validation.
*/
protected void validateConstructorInvocation(InvocationContext ctx) throws Exception {
ExecutableValidator executableValidator = validatorInstance.get().forExecutables();
Set<? extends ConstraintViolation<?>> violations = executableValidator
.validateConstructorParameters(ctx.getConstructor(), ctx.getParameters());
if (!violations.isEmpty()) {
throw new ConstraintViolationException(getMessage(ctx.getConstructor(), ctx.getParameters(), violations),
violations);
}
ctx.proceed();
Object createdObject = ctx.getTarget();
violations = executableValidator.validateConstructorReturnValue(ctx.getConstructor(),
createdObject);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(getMessage(ctx.getConstructor(), ctx.getParameters(), violations),
violations);
}
}
private String getMessage(Member member, Object[] args, Set<? extends ConstraintViolation<?>> violations) {
StringBuilder message = new StringBuilder();View on GitHub (pinned to e1c734241f)
Solutions
- Read the violations from getConstraintViolations() to identify the offending parameter index and constraint.
- Correct the arguments passed to the constructor, or validate config earlier (e.g. via @ConfigMapping with validation).
- Adjust or remove the constructor-parameter constraints if they are too strict for legitimate inputs.
- Pre-validate inputs before requesting the bean instance from CDI.
Example fix
// before
public Worker(@Min(1) int threads) { ... }
Container.instance().select(Worker.class) with threads=0 // throws
// after
Container.instance().select(Worker.class) with threads=1; // passes @Min(1) Defensive patterns
Strategy: validation
Validate before calling
Set<? extends ConstraintViolation<?>> v = validator.forExecutables().validateConstructorParameters(ctor, args);
if (!v.isEmpty()) { /* do not instantiate */ } Type guard
boolean canConstruct = args[0] != null && threads >= 1; // mirror declared constraints
Try / catch
try { Worker w = instance.get(); } catch (ConstraintViolationException e) { // constructor never ran; inspect violations } Prevention
- Mirror constructor constraints in factory/creator code before instantiating
- Use @ConfigMapping validation for configuration instead of constructor constraints
- Test bean creation with boundary argument values
- Catch ConstraintViolationException at bean-acquisition boundaries and report config errors clearly
When it happens
Trigger: Instantiating a bean whose constructor parameters carry constraints (e.g. @NotNull String config, @Min(1) int threads) via CDI with method validation enabled, passing invalid arguments; thrown at AbstractMethodValidationInterceptor.java:101-104 before ctx.proceed().
Common situations: Programmatic CDI lookup or Instance.get() with invalid constructor arguments; factory classes creating validated beans with config values that fail @Min/@Max/@Pattern; misconfigured application properties injected through constrained constructors.
Related errors
- (dynamic: constructor return value constraint violations sum
- Multiple @Inject constructors on ${theClass}
- @CachedResults class must be an interface or declare a no-ar
- (dynamic: parameter constraint violations summary for the in
- (dynamic: return value constraint violations summary for the
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/015df3ac07246fb5.
Report an issue: GitHub.