[bv-dev] When is a method validated

Emmanuel Bernard emmanuel at hibernate.org
Tue Feb 28 04:27:43 EST 2012


I personally feel uneasy about having the behavior change depending on how visible annotations are to the client even though I understand the reasoning. As I said, interceptor messing around parameter and return values are not very common and one could clearly put interceptors not complying with the constraints under the programming error. I am reluctant to introduce an option to alter the behavior.

That being said. Java EE 7 plans on making interceptors configuration generic. So it's likely that one person will be able to reorder its interceptors or even write its own.

Emmanuel

On 28 févr. 2012, at 00:28, Michael Nascimento wrote:

> Ok, let's complicate matters a little bit:
> 
> If a bean is exposed through an interface and therefore constraints
> are applied to the implementation, obviously parameter validation
> should happen right before invoking the method and return validation
> should happen right after return. In this case, validation constraints
> are completely opaque for the original caller and certainly they are
> not part of the API.
> 
> If a bean is exposed *directly* to the caller, constraints are part of
> the API exposed to the caller. They are part of the contract pretty
> much like possible thrown checked exceptions and all, so it would make
> more sense to validate parameters right after the caller invokes it
> and validate the return value right before delivering it to the
> caller. Then, the API does what it says.
> 
> Does this different behaviour sound complicated? Yes, but this is
> technically the correct thing to do if you think about validation
> being part of the API or not. As cumbersome as it seems, it is
> possible to implement it using CDI since it allows one to get the
> exact InjectionTarget and check for the API rule above. Should it be
> done that way? That is open to discussion, but I am pretty sure other
> people will reason it the way I just did.
> 
> Regards,
> Michael
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev




More information about the beanvalidation-dev mailing list