bval-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Blevins (JIRA)" <>
Subject [jira] [Created] (BVAL-174) Return Parameter Validation Ignore void methods
Date Mon, 13 May 2019 09:19:00 GMT
David Blevins created BVAL-174:

             Summary: Return Parameter Validation Ignore void methods
                 Key: BVAL-174
             Project: BVal
          Issue Type: Improvement
    Affects Versions: 2.0.0
            Reporter: David Blevins
             Fix For: 2.0.3

Given the following annotation:

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Set;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@javax.validation.Constraint(validatedBy = {Audience.Constraint.class})
public @interface Audience {

    String value();

    Class<?>[] groups() default {};

    String message() default "The 'aud' claim must contain '{value}'";

    Class<? extends Payload>[] payload() default {};

    class Constraint implements ConstraintValidator<Audience, JsonWebToken> {
        private Audience audience;

        public void initialize(final Audience constraint) {
            this.audience = constraint;

        public boolean isValid(final JsonWebToken value, final ConstraintValidatorContext
context) {
            final Set<String> audience = value.getAudience();
            return audience != null && audience.contains(this.audience.value());

BVal wil successfully avoid throwing errors when placed on a method like the following:

    @RolesAllowed({"manager", "user"})
    public Movie getMovie() {
        return new Movie(1, "The Matrix", "Lana Wachowski");

However on a method that returns void an exception will be throwing stating BVal cannot find
a ConstraintValidator for return type void.

    public void addMovie(Movie newMovie) {
        store.put(newMovie.getId(), newMovie);

If the BValInterceptor is updated to ignore checking return values of void methods, it appears
to pass the Bean Validation TCK and solves the issue.

This message was sent by Atlassian JIRA

View raw message