Hi,<div class="gmail_extra"><br><div class="gmail_quote">2012/11/7 Hardy Ferentschik <span dir="ltr">&lt;<a href="mailto:hardy@hibernate.org" target="_blank">hardy@hibernate.org</a>&gt;</span><br><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">

Hi,<br>
<br>
I think I would like to clarify a few things first. We keep just talking about getters.<br>
What does this actually mean? Do we talk about any method starting with &#39;get&#39; or<br>
do we mean getters for properties in the Java Bean sense (aka getters for fields with<br>
the matching name)?<br>
<br>
Do you want to exclude any method starting with &#39;get&#39; from method validation or just<br>
properties getters? If the latter, are we not introducing some quite arbitrary distinction<br>
between methods starting with &#39;get&#39;?<br>
<br>
Also what&#39;s about methods starting with &#39;is&#39;? Wouldn&#39;t we have to exclude them<br>
as well in this case?<br>
<br>
Also, in the current specification (1.0, 3.1.2. Field and property validation) is the intention<br>
to only validate a getter when it is a Java Bean property (backed up by a matching field)?<br>
I think this is not very clear and not explicitly tested in the TCK.<br></blockquote><div><br></div><div>A JavaBeans property IMO doesn&#39;t have to be backed by a field. Properties are identified looking for methods in the form<br>
</div>
<div>
                
        
        
                <pre><span style="font-size:10pt;font-family:Courier">public &lt;PropertyType&gt; get&lt;PropertyName&gt;();
public void set&lt;PropertyName&gt;(&lt;PropertyType&gt; a);
</span></pre></div><div>There may be read-/writable, read-only and write-only properties, For boolean properties the form</div><div><br></div>
                
        
        <div><span style="font-family:Courier;font-size:10pt">public boolean is&lt;PropertyName&gt;();</span></div><div><br></div><div>is allowed for the read method (see [1] and [2]). There may also be properties which are computed dynamically.</div>
<div><br></div><div>So AFAICS we would have to exclude all methods adhering to the pattern <span style="font-family:Courier;font-size:10pt">&lt;PropertyType&gt; {get|is}&lt;PropertyName&gt;()</span> from method-validation. As outlined before this would be kind of irregular.</div>
<div><br></div><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"><div><br>
On 6 Jan 2012, at 6:53 PM, Emmanuel Bernard wrote:<br>
<br>
&gt; If we treat getters as regular methods, we would add a new<br>
&gt; behavior to all existing constrained beans. Things that were constrained<br>
&gt; at specific lifecycles boundaries would now be constrained every time a<br>
&gt; getter is called. That would break backward compatibility.<br>
<br>
</div>Backward compatibility is indeed an issue. However, instead of imo arbitrarily<br>
considering a getXYZ not as a method, I would have just not enabled method validation<br>
out of the box. I would have made it an active choice.</blockquote><div><br></div><div>Right, in case a user actively enables method validation, there should be no surprise for the user if getter methods are validated upon invocation. That&#39;s also the approach followed by Seam Validation and Spring 3.1, both integrating with the proprietary method validation feature of Hibernate Validator 4.2. I&#39;m also not aware of any issue, bug report in HV etc. regarding getters being validated.</div>
<div> </div><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">Alternatively I would add an option<br>
to switch between ignoring getters and taking them into consideration for method validation.<br>
However, I don&#39;t think  @ValidateOnCall is a good option though. This seems to me to<br>
intrusive. I rather add a configuration option for the ValidatorFactory.<br></blockquote><div><br></div><div>A configuration option on VF might indeed be a possibility. I think validating getter methods should be the default setting :)</div>
<div> <br></div><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">
<div><br>
&gt; Even if a getter was to be constrained on call - you would probably want<br>
&gt; to constrain on the setter<br>
<br>
</div>What if other method modify the state of the property (not just a setter). Maybe the intend<br>
is to verify that the object is in a certain state when I request it.<br>
<div><br>
&gt; But I do like the simplicity of the rule claiming that all methods<br>
&gt; are constrained regardless of their similarity to the Bean<br>
&gt; specification. I do not currently thing that this argument alone<br>
&gt; outweighs the other problems.<br>
<br>
</div>I think it is a argument for consistency. Excluding getter methods from a general method validation<br>
framework seems to introduce unnecessary inconsistency and might even exclude the framework<br>
as general method validation framework of choice.<br></blockquote><div><br></div><div>+1</div><div> </div><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">

<div><br>
&gt; ### Forcing a getter to behave as a regular method<br>
&gt;<br>
&gt; To solve this use case, we can introduce a `@ValidateOnCall`<br>
&gt; annotation that should be placed on the getter method.<br>
<br>
</div>See above.<br></blockquote><div><br></div><div>No big fan of an annotation either. Globally configuring this makes more sense IMO. If really fine-grained control is required, validation groups may be used.</div><div>
 </div><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">
<span><font color="#888888"><br>
--Hardy<br></font></span></blockquote><div><br></div><div>--Gunnar</div><div><br></div><div>[1] <a href="http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html" target="_blank">http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html</a></div>
<div>[2] <a href="http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/" target="_blank">http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/</a></div><div><br></div><div> </div>
<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"><span><font color="#888888">
</font></span><div><div><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>