<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Yes it would. That was my question earlier in this thread. Do we consider the intersection trick acceptable in the specification.&nbsp;<br><br>On 7 déc. 2012, at 00:41, Gunnar Morling &lt;<a href="mailto:gunnar@hibernate.org">gunnar@hibernate.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>Regarding BVAL-221, wouldn't that be fixed by the intersection type approach I suggested? Or do you think it we shouldn't pursue it because its too magic or uncommon?<br><div class="gmail_extra"><br><br><div class="gmail_quote">
2012/12/5 Emmanuel Bernard <span dir="ltr">&lt;<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
addNode(CLASS_LEVEL) is not a bad idea. The alternative is a full method<br>
as proposed in BVAL-191.<br>
<br>
Unfortunately, we cannot solve the problem with this method because of<br>
the second use case I describe in the email below. This example does not<br>
work even if does not make use of addNode(null) :(<br>
<span class="HOEnZb"><font color="#888888"><br>
Emmanuel<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Wed 2012-12-05 14:10, Hardy Ferentschik wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; Thanks for the clarification. Indeed I was forgetting about the special meaning of null in this case (should have read section 5.2 of the spec).<br>
&gt; In this context adding addNode(null) is indeed "natural" in the sense that it strictly follows the spec. That said, it still looks awkward to me.<br>
&gt; Couldn't there be for example a constant so that you could do something like addNode(CLASS_LEVEL). I find this much more telling.<br>
&gt; In this light option 4 - adding a different method - of your proposed solution on <a href="http://beanvalidation.org/proposals/BVAL-221/" target="_blank">http://beanvalidation.org/proposals/BVAL-221/</a> sounds more appealing again.<br>

&gt; What about adding addClassLevelNode()?<br>
&gt;<br>
&gt; --Hardy<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On 4 Jan 2012, at 4:42 PM, Emmanuel Bernard &lt;<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; These are good questions<br>
&gt; &gt;<br>
&gt; &gt; ## Natural way to do it?<br>
&gt; &gt;<br>
&gt; &gt; Assuming<br>
&gt; &gt;<br>
&gt; &gt; @HasCorrectHomeAddressFromTop<br>
&gt; &gt; class Order {<br>
&gt; &gt; &nbsp;@HasCorrectHomeAddressFromUser<br>
&gt; &gt; &nbsp;User user;<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt; class User {<br>
&gt; &gt; &nbsp;@CollectionNotEmpty<br>
&gt; &gt; &nbsp;@HasCorrectHomeAddressFromAddresses<br>
&gt; &gt; &nbsp;Map&lt;String,Address&gt; addresses;<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt; When `HasCorrectHomeAddressFromTop` is validated, you can attach a<br>
&gt; &gt; `ConstraintViolation` to Order.user.addresses["home"] with the<br>
&gt; &gt; following call and it works in BV 1.0<br>
&gt; &gt; This is how the API is supposed to be used.<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; &nbsp;context.buildConstraintViolationWithTemplate( "Incorrect home address" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( "user" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( "addresses" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "home" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;<br>
&gt; &gt; following this logic, when `HasCorrectHomeAddressFromUser` is validated,<br>
&gt; &gt; you can attach a `ConstraintViolation` with the following call but that<br>
&gt; &gt; does not work in BV 1.0.<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; &nbsp;context.buildConstraintViolationWithTemplate( "Incorrect home address" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( "addresses" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "home" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;<br>
&gt; &gt; When `HasCorrectHomeAddressFromAddresses` is validated, you can attach a<br>
&gt; &gt; `ConstraintViolation` with the following call but that does not work<br>
&gt; &gt; in BV 1.0.<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; &nbsp;context.buildConstraintViolationWithTemplate( "Incorrect home address" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( null )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "home" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;<br>
&gt; &gt; Not that we use null as we add a class level constraint violation to the<br>
&gt; &gt; element in `addresses["home"]`.<br>
&gt; &gt;<br>
&gt; &gt; For you info, when `CollectionNotEmpty` is validated, you can attach a<br>
&gt; &gt; `ConstraintViolation` with the following call.<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; &nbsp;context.buildConstraintViolationWithTemplate( "collection empty" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;<br>
&gt; &gt; ## Loss in type-safety<br>
&gt; &gt;<br>
&gt; &gt; If we add `inIterable()` to `NodeBuilderDefinedContext` we solve our<br>
&gt; &gt; problem but we introduce a leak in the type safety. I could do the<br>
&gt; &gt; following calls<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; &nbsp;context.buildConstraintViolationWithTemplate( "Incorrect home address" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( null )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "home" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "wc" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;<br>
&gt; &gt; This call is not correct as no node has been (explicitly) created<br>
&gt; &gt; between the two inIterable() calls. The correct call would be<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; &nbsp;context.buildConstraintViolationWithTemplate( "Incorrect WC location" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( null )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "home" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode( null )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.inIterable().atKey( "wc" )<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;<br>
&gt; &gt; Here we are assuming that the `addresses` elements contain map.<br>
&gt; &gt;<br>
&gt; &gt; We could add in the spec that subsequent calls to `inIterable()`<br>
&gt; &gt; implicitly create a node without name.<br>
&gt; &gt;<br>
&gt; &gt; The problem is not as critical as I imagined but that would require<br>
&gt; &gt; adding some magic rules wrt node creation.<br>
&gt; &gt;<br>
&gt; &gt; Also imagine a user willing to validate a property of Address, could he<br>
&gt; &gt; forget to call the node creation method?<br>
&gt; &gt;<br>
&gt; &gt; Emmanuel<br>
&gt; &gt;<br>
&gt; &gt; On Mon 2012-11-26 13:07, Hardy Ferentschik wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; On 23 Jan 2012, at 2:48 PM, Emmanuel Bernard &lt;<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>&gt; wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;&gt; The question is do we want to do that or lean towards one of the<br>
&gt; &gt;&gt;&gt; alternative methods:<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; - an explicit new method deprecating addNode<br>
&gt; &gt;&gt;&gt; - relaxing NodeBuilderDefinedContext and adding the new contract on it<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; In the proposal you are saying about relaxing NodeBuilderDefinedContext: &nbsp;"But that would break the contextual<br>
&gt; &gt;&gt; and safety of the API as this interface is also returned by atKey and atIndex."<br>
&gt; &gt;&gt; Can you provide an example?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Also in the proposal you are saying that:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; context.buildConstraintViolationWithTemplate("oh noes")<br>
&gt; &gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;.addNode(null) //ie the contained element<br>
&gt; &gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inIterable().atKey(someKey)<br>
&gt; &gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;.addConstraintViolation();<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; would be the natural solution. Why is ".addNode(null)" natural and why could we not have inIterable() directly<br>
&gt; &gt;&gt; on ConstraintViolationBuilder?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; --Hardy<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; _______________________________________________<br>
&gt; &gt;&gt; beanvalidation-dev mailing list<br>
&gt; &gt;&gt; <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; beanvalidation-dev mailing list<br>
&gt; &gt; <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; beanvalidation-dev mailing list<br>
&gt; <a href="mailto:beanvalidation-dev@lists.jboss.org">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>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">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>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>beanvalidation-dev mailing list</span><br><span><a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a></span><br><span><a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a></span><br></div></blockquote></body></html>