quarkusio/quarkus · error · ConstraintViolationException
(dynamic: return value constraint violations summary for the
Error message
(dynamic: return value constraint violations summary for the invoked method)
What it means
This ConstraintViolationException is thrown by the method-validation interceptor AFTER the method body has already executed and returned, when ExecutableValidator.validateReturnValue finds the returned value violates constraints declared on the method (e.g. @NotNull on the return type or on elements of the returned collection). The method's side effects already happened even though its result is rejected.
Source
Thrown at extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/interceptor/AbstractMethodValidationInterceptor.java:78
* 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.
*
* @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 {View on GitHub (pinned to e1c734241f)
Solutions
- Fix the bean implementation so the returned value satisfies the declared constraints (return Optional instead of null, filter invalid elements).
- Relax or remove the return-value constraint annotation if returning null/invalid values is legitimate.
- Check the violation set for the exact property path; if cascading (@Valid) is involved, fix the nested object's fields.
- For query-style methods, use Optional<T> return types instead of @NotNull + null.
Example fix
// before
@NotNull
public User find(String id) { return repo.find(id); } // may return null
// after
public Optional<User> find(String id) { return Optional.ofNullable(repo.find(id)); } Defensive patterns
Strategy: validation
Validate before calling
Set<ConstraintViolation<Object>> v = validator.forExecutables().validateReturnValue(target, method, result);
if (!v.isEmpty()) { /* result violates declared constraints */ } Type guard
boolean isValidResult = result != null; // for a @NotNull-returning method call site
Try / catch
try { User u = service.find(id); } catch (ConstraintViolationException e) { // side effects may have occurred; inspect e.getConstraintViolations() } Prevention
- Avoid @NotNull on methods that can legitimately find nothing; prefer Optional
- Unit-test validated methods' return paths including null/empty cases
- Remember the method body already ran — design methods so a rejected return value is not harmful
- Cascade @Valid only where nested constraint reports are useful
When it happens
Trigger: A validated bean method returns a value violating its return-value constraints (e.g. returns null where @NotNull return type is declared, or a list containing null elements under @NotNull List<@NotNull T>); thrown at AbstractMethodValidationInterceptor.java:77-80 after ctx.proceed().
Common situations: A repository method annotated with @NotNull return returns null when a row is missing; a service returning an optional result as null; adding return-type constraints to legacy methods whose implementations sometimes return null.
Related errors
- (dynamic: parameter constraint violations summary for the in
- (dynamic: constructor parameter constraint violations summar
- (dynamic: constructor return value constraint violations sum
- Fruit Name was not set on request.
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/e1d44c3645b28350.
Report an issue: GitHub.