<div dir="ltr">Hi Gunnar,<div><br></div><div>In order to preserve compatibility, I think we should require a specific option to be set in the factory to enable array element validation. This way, new projects have full support. What do you think?</div><div><br></div><div>Regards,</div><div>Michael</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 19, 2017 at 9:04 AM, Gunnar Morling <span dir="ltr">&lt;<a href="mailto:gunnar@hibernate.org" target="_blank">gunnar@hibernate.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2017-04-19 13:46 GMT+02:00 Emmanuel Bernard &lt;<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>&gt;:<br>
&gt; What you are inferring is that the JLS made an incompatible move right?<br>
&gt; Because before Java 8, @Size(max=5) String[] was meant to be applied on<br>
&gt; the array right?<br>
<br>
</span>It&#39;s not incompatible. Before, there were no TYPE_USE annotations. But<br>
now, an annotation can be both at the same time:<br>
<br>
    &quot;It is possible for @Foo to be both a declaration annotation and a<br>
type annotation simultaneously.&quot;<br>
<br>
The thing is that we added TYPE_USE as supported element type for all<br>
built-in annotations, so we now cannot tell apart whether that @Email<br>
is meant as field-level constraint (targeting the array) or as type<br>
annotation (targeting the component type). A new constraint annotation<br>
member or defined payload could be used to provide that information,<br>
but I&#39;d prefer implementations to experiment with that first.<br>
<span class=""><br>
&gt;<br>
&gt; Anyways, I don&#39;t think that would be a massive loss to lose array<br>
&gt; support but my background is biased toward preferring collections.<br>
<br>
</span>Yes, my thinking, too. It should be possible to add later, though. In<br>
that light spending the cycles on array support wasn&#39;t for nothing,<br>
e.g. we found names (&quot;container element constraints&quot;) which will work<br>
for both usages down the road.<br>
<div class="HOEnZb"><div class="h5"><br>
&gt;<br>
&gt; Emmanuel<br>
&gt;<br>
&gt; On Wed 17-04-19 10:27, Gunnar Morling wrote:<br>
&gt;&gt;Hi,<br>
&gt;&gt;<br>
&gt;&gt;Guillaume made an important observation concerning the validation of<br>
&gt;&gt;array elements. So far we envisioned to support this:<br>
&gt;&gt;<br>
&gt;&gt;    String @Email [] emails;<br>
&gt;&gt;<br>
&gt;&gt;That looks nice (provided that @Email supports TYPE_USE), only that<br>
&gt;&gt;it&#39;s getting semantics of type annotations for arrays wrong.<br>
&gt;&gt;<br>
&gt;&gt;As per the JLS [1], the @Email annotation here applies to the array<br>
&gt;&gt;type String[], not the component type String. This example from the<br>
&gt;&gt;JLS clarifies the intent:<br>
&gt;&gt;<br>
&gt;&gt;    @C int @A [] @B [] f;<br>
&gt;&gt;<br>
&gt;&gt;    &quot;@A applies to the array type int[][], @B applies to its component<br>
&gt;&gt;type int[],<br>
&gt;&gt;    and @C applies to the element type int.&quot;<br>
&gt;&gt;<br>
&gt;&gt;So according to that, our example would have to be:<br>
&gt;&gt;<br>
&gt;&gt;    @Email String[] emails;<br>
&gt;&gt;<br>
&gt;&gt;But obviously this conflicts with the existing semantics of applying<br>
&gt;&gt;constraints to arrays (not their elements) in BV 1.1.<br>
&gt;&gt;<br>
&gt;&gt;So based on that, I don&#39;t see a good way for supporting container<br>
&gt;&gt;element constraints for arrays. Hence my suggestion is to not support<br>
&gt;&gt;them in the BV 2.0 spec (the validation of container elements of<br>
&gt;&gt;generic containers - List&lt;@Email String&gt; - is not affected). Specific<br>
&gt;&gt;implementations may explore ways around it (e.g. specifying the target<br>
&gt;&gt;via payload()) and we may revisit it in 2.1.<br>
&gt;&gt;<br>
&gt;&gt;Any thoughts?<br>
&gt;&gt;<br>
&gt;&gt;--Gunnar<br>
&gt;&gt;<br>
&gt;&gt;[1] <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.7.4" rel="noreferrer" target="_blank">https://docs.oracle.com/<wbr>javase/specs/jls/se8/html/jls-<wbr>9.html#jls-9.7.4</a><br>
&gt;&gt;____________________________<wbr>___________________<br>
&gt;&gt;beanvalidation-dev mailing list<br>
&gt;&gt;<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
&gt;&gt;<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
&gt; ______________________________<wbr>_________________<br>
&gt; beanvalidation-dev mailing list<br>
&gt; <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
______________________________<wbr>_________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
</div></div></blockquote></div><br></div>