Well yes as you can imagine I do think getters should not be considered
methods. Let me try and give you my arguments.
## Backward compatibility
If we treat getters as regular methods, we would add a new
behavior to all existing constrained beans. Things that were constrained
at specific lifecycles boundaries would now be constrained every time a
getter is called. That would break backward compatibility.
Even if a getter was to be constrained on call - you would probably want
to constrain on the setter - it's quite unlikely that existing attribute
style constraints would be the same as the method ones. They would likely
use different groups.
## 80% - 20% rule
It seems to be that amongst the getXxx() methods, there is a whole
lot more getters than action methods. That's why making getXxx()
act as attributes does fly for me.
## Interception technology
Someone could mitigate the backward compatibility issue by arguing
that CDI beans are not that often hosting getters.
I am not sure that is true but even if it was, this eclipses more
thorough interception technologies like AspectJ which could intercept
all getter calls even possibly from the JPA or other bean data
providers.
## But
But I do like the simplicity of the rule claiming that all methods
are constrained regardless of their similarity to the Bean
specification. I do not currently thing that this argument alone
outweighs the other problems.
Regardless, there are situations where action methods look like
getters.
### Forcing a getter to behave as a regular method
To solve this use case, we can introduce a `@ValidateOnCall`
annotation that should be placed on the getter method.
### Should we leave this undefined in the spec?
A "solution" could be to leave this undefined in the specification
and let providers provide the right mechanisms.
I don't think this would be the right approach. This is an important
enough use case for us to cover it I think. Additional means of
adjusting the behavior can be left to providers.
What do you think?
Emmanuel
On Sat 2012-11-03 16:36, Gunnar Morling wrote:
> I have my own ideas, but I'd like to get your opinion on the
subject.
So what's your take on this, Emmanuel?
Handling getters as normal methods in the spec and leaving it to providers
to make other behavior configurable seems reasonable to me.
--Gunnar
2012/10/27 Hardy Ferentschik <hardy(a)hibernate.org>
>
>
>
>
> On 26 Oct 2012, at 19:31, Gunnar Morling <gunnar(a)hibernate.org> wrote:
>
> > I think getters should be handled as any other methods during method
> validation.
>
> +1
>
> > Not considering them during method validation would IMO be some form
> > irregularity, causing getter-named methods not to be validated
> > although a user might expect it:
>
> +1
> >From the method validation point of view there is just no reason to treat
> getXYZ() differently.
> I rather have two validations of the same constraints happening, but I
> don't think it will be a big problem in most cases.
>
> A provider could always choose to make it configurable.
>
> --hardy
>
>
>
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/beanvalidation-dev
>
_______________________________________________
beanvalidation-dev mailing list
beanvalidation-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/beanvalidation-dev