2012/11/8 Emmanuel Bernard <span dir="ltr">&lt;<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>&gt;</span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


A property according to the JavaBeans specification is either:<br>
<br>
- a pair of [PropertyType] get[PropertyName]() / void set[PropertyName]([PropertyType] value)<br>
- a  [PropertyType] get[PropertyName]()<br>
- a void set[PropertyName]([PropertyType] value)<br>
- if PropertyType is boolean, then boolean is[PropertyName]() is accepted (and preferred)<br>
<br>
There are ways to customize that further but that&#39;s out of the scope of this discussion. So to answer your question backing fields are an implementation detail.<br>
<br>
You and Gunnar seem to want a global VF level flag to activate/inactivate getters as constrained methods. I would like to know your reasons for that. When I put myself in situations and try and use method level validations, I can&#39;t seem to find it compelling to get a global flag. It would only let me chose between two evils instead of giving me choice on a per element basis.<br>


</blockquote><div><br></div><div>Generally I don&#39;t think that considering getters during method validation really is a problem. So I wouldn&#39;t really have a problem with this being the default behavior (which it also is in the proprietary API in HV 4.3). I&#39;d prefer that over excluding certain named methods from method validation as this goes against the principle of least surprise and would feel like an inconsistency to me.</div>
<div><br></div><div>But if validating getters during method validation really is a problem, I&#39;d expect this to be the case generally throughout an application or system. Taking the example of JPA entities which used to be validated upon persisting only and now would their property constraints get validated upon getter invocation, then I&#39;d prefer to disable getter validation globally instead of marking each individual property with an annotation.</div>

<div><br></div><div>If I as a user really needed a configuration per element, I could do so using validation groups. If for instance single constraints should not be validated upon getter invocation, I could use a group like this:</div>
<br>public static class Foo {<br><br>    //doesn&#39;t get validated during method validation of Default group<br>    @NotNull(groups=AllConstraints.class)<br>    private String getBar() { ... }<br><br>    //does get validated during method validation<br>
    @NotNull<br>    private String getBaz() { ... }<br>}<br><br>//use this e.g. to validate upon entity persisting<br>public interface AllConstraints extends Default {}</div><div class="gmail_quote"><br></div><div class="gmail_quote">
Therefore I feel we shouldn&#39;t introduce a new mechanism such as <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">@ValidateOnCall since the use case is already covered by existing concepts.</span></div>
<div class="gmail_quote"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></span></div><div class="gmail_quote"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Additionally, an annotation might not be the right vehicle for cases where only single constraints of a given getter shall be excluded from method validation while other constraints on the same getter should be considered.</span></div>
<div class="gmail_quote"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></span></div><div class="gmail_quote"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">--Gunnar</span></div>
<div class="gmail_quote"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></span></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<br>
We already discussed the merits of having method validation activated by default vs the other way around in the past but if I follow your argument, I will ask developers who add constraints to their methods to also create a META-INF/validation.xml in their various modules to activate method validation ? That seems to go against the current trend to me.<br>



<span><font color="#888888"><br>
Emmanuel<br>
</font></span><div><div><br>
On 7 nov. 2012, at 12:36, Hardy Ferentschik &lt;<a href="mailto:hardy@hibernate.org" target="_blank">hardy@hibernate.org</a>&gt; wrote:<br>
<br>
&gt; Hi,<br>
&gt;<br>
&gt; I think I would like to clarify a few things first. We keep just talking about getters.<br>
&gt; What does this actually mean? Do we talk about any method starting with &#39;get&#39; or<br>
&gt; do we mean getters for properties in the Java Bean sense (aka getters for fields with<br>
&gt; the matching name)?<br>
&gt;<br>
&gt; Do you want to exclude any method starting with &#39;get&#39; from method validation or just<br>
&gt; properties getters? If the latter, are we not introducing some quite arbitrary distinction<br>
&gt; between methods starting with &#39;get&#39;?<br>
&gt;<br>
&gt; Also what&#39;s about methods starting with &#39;is&#39;? Wouldn&#39;t we have to exclude them<br>
&gt; as well in this case?<br>
&gt;<br>
&gt; Also, in the current specification (1.0, 3.1.2. Field and property validation) is the intention<br>
&gt; to only validate a getter when it is a Java Bean property (backed up by a matching field)?<br>
&gt; I think this is not very clear and not explicitly tested in the TCK.<br>
&gt;<br>
&gt;<br>
&gt; On 6 Jan 2012, at 6:53 PM, Emmanuel Bernard wrote:<br>
&gt;<br>
&gt;&gt; If we treat getters as regular methods, we would add a new<br>
&gt;&gt; behavior to all existing constrained beans. Things that were constrained<br>
&gt;&gt; at specific lifecycles boundaries would now be constrained every time a<br>
&gt;&gt; getter is called. That would break backward compatibility.<br>
&gt;<br>
&gt; Backward compatibility is indeed an issue. However, instead of imo arbitrarily<br>
&gt; considering a getXYZ not as a method, I would have just not enabled method validation<br>
&gt; out of the box. I would have made it an active choice. Alternatively I would add an option<br>
&gt; to switch between ignoring getters and taking them into consideration for method validation.<br>
&gt; However, I don&#39;t think  @ValidateOnCall is a good option though. This seems to me to<br>
&gt; intrusive. I rather add a configuration option for the ValidatorFactory.<br>
&gt;<br>
&gt;&gt; Even if a getter was to be constrained on call - you would probably want<br>
&gt;&gt; to constrain on the setter<br>
&gt;<br>
&gt; What if other method modify the state of the property (not just a setter). Maybe the intend<br>
&gt; is to verify that the object is in a certain state when I request it.<br>
&gt;<br>
&gt;&gt; But I do like the simplicity of the rule claiming that all methods<br>
&gt;&gt; are constrained regardless of their similarity to the Bean<br>
&gt;&gt; specification. I do not currently thing that this argument alone<br>
&gt;&gt; outweighs the other problems.<br>
&gt;<br>
&gt; I think it is a argument for consistency. Excluding getter methods from a general method validation<br>
&gt; framework seems to introduce unnecessary inconsistency and might even exclude the framework<br>
&gt; as general method validation framework of choice.<br>
&gt;<br>
&gt;&gt; ### Forcing a getter to behave as a regular method<br>
&gt;&gt;<br>
&gt;&gt; To solve this use case, we can introduce a `@ValidateOnCall`<br>
&gt;&gt; annotation that should be placed on the getter method.<br>
&gt;<br>
&gt; See above.<br>
&gt;<br>
&gt; --Hardy<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; beanvalidation-dev mailing list<br>
&gt; <a href="mailto:beanvalidation-dev@lists.jboss.org" target="_blank">beanvalidation-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
<br>
_______________________________________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org" target="_blank">beanvalidation-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
</div></div></blockquote></div><br></div>