<div dir="ltr"><div>Ahh, I see, it&#39;s a part of the spec. So basically if we wanted to do it the other </div><div>way there&#39;s no other option then remove the @WithAnnotations, receive all</div><div>PATs and do the filtering on our side, right? </div><div><br></div><div>And also thanks for a quick response!</div><div><br></div><div>Have a nice day, </div><div>Marko</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-05-02 17:25 GMT+02:00 Martin Kouba <span dir="ltr">&lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Marko,<br>
<br>
comments inline...<br>
<br>
Dne 2.5.2018 v 16:57 Marko Bekhta napsal(a):<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br>
<br>
In Hibernate Validator CDI extension we are using @WithAnnotations to filter<br>
beans that potentially need to be validated (for actual usage see [1]):<br>
<br>
public &lt;T&gt; void processAnnotatedType(@Observes @WithAnnotations({<br>
Constraint.class,<br>
Valid.class,<br>
ValidateOnExecution.class<br>
}) ProcessAnnotatedType&lt;T&gt; processAnnotatedTypeEvent) {<br>
// doing something ...<br>
}<br>
<br>
The problem that we&#39;ve stumbled upon is that it looks like this filtering does<br>
not take into account the information from implemented interfaces. For example<br>
let&#39;s assume we have an interface:<br>
<br>
@ValidateOnExecution(type = ExecutableType.ALL)<br>
public interface ShipmentService {<br>
public void findShipment(@NotNull String id);<br>
}<br>
<br>
which is implemented by ShipmentServiceImpl:<br>
<br>
public class ShipmentServiceImpl implements ShipmentService {<br>
<br>
@Override<br>
public void findShipment(String id) {<br>
}<br>
}<br>
<br>
Our expectation would be that as interface is marked with one of the annotations<br>
listed among values of @WithAnnotations filter, the corresponding bean<br>
(ShipmentServiceImpl) would be pushed to processAnnotatedType(..) method. But it<br>
is not. As a result we don&#39;t create a validation proxy and corresponding service<br>
bean never performs any validation operations.  In case when any of the filtered<br>
annotations is added to the impl bean things start to work (impl bean is processed).<br>
<br>
The above case shows placement of annotation on a type level, but similar<br>
behavior is observed in cases when annotation is on a method level.<br>
<br>
As forcing presence of one of the annotations from the filter list on a impl<br>
beans is not really an option, an alternative could be to drop the<br>
@WithAnnotations filtering completely. Which is also not that great, as<br>
dropping the filtering would mean that:<br>
<br>
- Validation extension would need to process all possible beans that are available<br>
- Such processing requires calls to Hibernate Validatior which must create the metadata<br>
for each bean hierarchy and store it, even if nobody actually needs to validate those<br>
beans.<br>
- This would lead to much greater memory consumption as well as longer bootstrap<br>
time. Which is not good.<br>
<br>
Hence we would like to ask if there is any particular reasons why @WithAnnotations<br>
</blockquote>
<br></div></div>
Well, the reason is that the spec requires this:<br>
<br>
&quot;If the annotation is applied, the container must only deliver ProcessAnnotatedType events for types which contain at least one of the annotations specified. The annotation can appear on the annotated type, or on any member, or any parameter of any member of the annotated type, as defined in Alternative metadata sources.&quot;<br>
<br>
See also <a href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#process_annotated_type" rel="noreferrer" target="_blank">http://docs.jboss.org/cdi/spec<wbr>/2.0/cdi-spec.html#process_<wbr>annotated_type</a><br>
<br>
Annotations should be inherited (and PAT fired) if @Inherited meta-annotation is used. But I&#39;m not quite sure this works. Also note that annotations are never inherited from interfaces (see also java.lang.annotation.Inherited javadoc)!<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
filter does not consider looking at super classes and implemented interfaces to check<br>
for annotations listed in @WithAnnotations?<br>
</blockquote>
<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
Have a nice day,<br>
Marko<br>
<br>
[1] <a href="https://github.com/hibernate/hibernate-validator/blob/master/cdi/src/main/java/org/hibernate/validator/cdi/ValidationExtension.java#L222" rel="noreferrer" target="_blank">https://github.com/hibernate/h<wbr>ibernate-validator/blob/master<wbr>/cdi/src/main/java/org/hiberna<wbr>te/validator/cdi/ValidationExt<wbr>ension.java#L222</a><br>
<br>
<br></span>
______________________________<wbr>_________________<br>
weld-dev mailing list<br>
<a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/weld-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailma<wbr>n/listinfo/weld-dev</a><br>
<br><span class="HOEnZb"><font color="#888888">
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
</font></span></blockquote></div><br></div>