quarkusio/quarkus · error · ConstraintViolationException

(dynamic: parameter constraint violations summary for the in

Error message

(dynamic: parameter constraint violations summary for the invoked method)

What it means

This is a jakarta.validation.ConstraintViolationException thrown by Quarkus's Hibernate Validator method-validation interceptor before the intercepted method runs. ExecutableValidator.validateParameters found at least one Bean Validation constraint violation among the method's arguments, so the method body is never executed. The message is dynamically built as 'N constraint violation(s) occurred during method validation' and lists the method, argument values, and each violation.

Source

Thrown at extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/interceptor/AbstractMethodValidationInterceptor.java:69

     * return value of the intercepted method.
     *
     * @param ctx The context of the intercepted method invocation.
     *
     * @return The result of the method invocation.
     *
     * @throws Exception Any exception caused by the intercepted method invocation.
     *         A {@link ConstraintViolationException} in case at least one
     *         constraint violation occurred either during parameter or
     *         return value validation.
     */
    protected Object validateMethodInvocation(InvocationContext ctx) throws Exception {

        ExecutableValidator executableValidator = validatorInstance.get().forExecutables();
        Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(ctx.getTarget(),
                ctx.getMethod(), ctx.getParameters());

        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(getMessage(ctx.getMethod(), ctx.getParameters(), violations),
                    violations);
        }

        Object result = ctx.proceed();

        violations = executableValidator.validateReturnValue(ctx.getTarget(), ctx.getMethod(), result);

        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(getMessage(ctx.getMethod(), ctx.getParameters(), violations),
                    violations);
        }

        return result;
    }

    /**
     * Validates the Bean Validation constraints specified at the parameters and/or
     * return value of the intercepted constructor.

View on GitHub (pinned to e1c734241f)

Solutions

  1. Inspect the ConstraintViolationException's getConstraintViolations() set to see exactly which parameter and constraint failed.
  2. Fix the caller to pass arguments satisfying the declared constraints, or relax the constraint annotations if the rules are too strict.
  3. For REST endpoints, map ConstraintViolationException to a 400 response via a dedicated ExceptionMapper (quarkus-hibernate-validator provides default handling) or ExceptionMapper<ConstraintViolationException>.
  4. Add @Valid on cascading parameters so nested violations are reported with full paths.

Example fix

// before
public void create(@NotNull @Size(min = 3) String name) { ... }
service.create("ab"); // throws ConstraintViolationException

// after
service.create("abc"); // passes @Size(min=3)
Defensive patterns

Strategy: validation

Validate before calling

Set<ConstraintViolation<Object>> violations = validator.forExecutables().validateParameters(target, method, args);
if (!violations.isEmpty()) { /* fix input or surface a 400 */ }

Type guard

boolean isValidParams = validator.forExecutables().validateParameters(bean, method, args).isEmpty();

Try / catch

try { service.create(name); } catch (ConstraintViolationException e) { violations = e.getConstraintViolations(); // log/return 400 }

Prevention

When it happens

Trigger: Calling a CDI bean method annotated for method validation (e.g. @ValidateOnExecution or automatic on REST/GraphQL endpoints) with arguments that violate @NotNull/@Size/@Min/@Pattern etc. declared on its parameters; the interceptor checks violations at AbstractMethodValidationInterceptor.java:68-71 and throws before ctx.proceed().

Common situations: Passing null to a @NotNull parameter; sending an oversized string to a @Size(max=...) parameter from a REST client; forgetting @Valid on a nested parameter bean so violations surface here instead of a nicer 400 response; calling internal beans directly in tests with invalid data.

Related errors


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