<div dir="ltr"><div>Hi,</div><div><br></div>FWIW, the main issue with BV 1.1 compatibility is that BV 1.1 supports:<div>[Example 1]</div><div>@Size(min = 2)</div><div>private String[] array;</div><div><br></div><div>which was the way to write that the array should have a minimum length of 2 (and was perfectly valid if the @Size constraint does not have a TYPE_USE target)</div><div><br></div><div>If we consider TYPE_USE support for arrays, according to the JLS, it should in fact be written:</div><div>[Example 2]<br></div><div>private String @Size(min = 2) [] array;</div><div><br></div><div>And the main compatibility issue is that the meaning of [Example 1] would not be compatible with the BV 1.1 behavior: it should mean that the String inside the array must have a minimum length of  2.</div><div><br></div><div>See the class I used as a playground here: <a href="https://github.com/gsmet/annotation-on-type-argument-array-bug/blob/master/src/main/java/org/hibernate/jdk/annotationontypeargumentarraybug/WrongAnnotationsReturnedForArrayTypeArgumentTest.java">https://github.com/gsmet/annotation-on-type-argument-array-bug/blob/master/src/main/java/org/hibernate/jdk/annotationontypeargumentarraybug/WrongAnnotationsReturnedForArrayTypeArgumentTest.java</a></div><div><br></div><div>-- </div><div>Guillaume</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 19, 2017 at 10:27 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: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>
Guillaume made an important observation concerning the validation of<br>
array elements. So far we envisioned to support this:<br>
<br>
    String @Email [] emails;<br>
<br>
That looks nice (provided that @Email supports TYPE_USE), only that<br>
it&#39;s getting semantics of type annotations for arrays wrong.<br>
<br>
As per the JLS [1], the @Email annotation here applies to the array<br>
type String[], not the component type String. This example from the<br>
JLS clarifies the intent:<br>
<br>
    @C int @A [] @B [] f;<br>
<br>
    &quot;@A applies to the array type int[][], @B applies to its component<br>
type int[],<br>
    and @C applies to the element type int.&quot;<br>
<br>
So according to that, our example would have to be:<br>
<br>
    @Email String[] emails;<br>
<br>
But obviously this conflicts with the existing semantics of applying<br>
constraints to arrays (not their elements) in BV 1.1.<br>
<br>
So based on that, I don&#39;t see a good way for supporting container<br>
element constraints for arrays. Hence my suggestion is to not support<br>
them in the BV 2.0 spec (the validation of container elements of<br>
generic containers - List&lt;@Email String&gt; - is not affected). Specific<br>
implementations may explore ways around it (e.g. specifying the target<br>
via payload()) and we may revisit it in 2.1.<br>
<br>
Any thoughts?<br>
<br>
--Gunnar<br>
<br>
[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>
______________________________<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>
</blockquote></div><br></div></div>