<div dir="ltr"><div>Hi all, </div><div><br></div><div>In Hibernate Validator CDI extension we are using @WithAnnotations to filter</div><div>beans that potentially need to be validated (for actual usage see [1]):</div><div><br></div><div>public &lt;T&gt; void processAnnotatedType(@Observes @WithAnnotations({</div><div><span style="white-space:pre">                </span>Constraint.class,</div><div><span style="white-space:pre">                </span>Valid.class,</div><div><span style="white-space:pre">                </span>ValidateOnExecution.class</div><div>}) ProcessAnnotatedType&lt;T&gt; processAnnotatedTypeEvent) {</div><div><span style="white-space:pre">        </span>// doing something ...</div><div>} </div><div><br></div><div>The problem that we&#39;ve stumbled upon is that it looks like this filtering does</div><div>not take into account the information from implemented interfaces. For example</div><div>let&#39;s assume we have an interface:</div><div><br></div><div>@ValidateOnExecution(type = ExecutableType.ALL)</div><div>public interface ShipmentService {</div><div><span style="white-space:pre">        </span>public void findShipment(@NotNull String id);</div><div>}</div><div><br></div><div>which is implemented by ShipmentServiceImpl:</div><div><br></div><div>public class ShipmentServiceImpl implements ShipmentService {</div><div><br></div><div><span style="white-space:pre">        </span>@Override</div><div><span style="white-space:pre">        </span>public void findShipment(String id) {</div><div><span style="white-space:pre">        </span>}</div><div>}</div><div><br></div><div>Our expectation would be that as interface is marked with one of the annotations</div><div>listed among values of @WithAnnotations filter, the corresponding bean</div><div>(ShipmentServiceImpl) would be pushed to processAnnotatedType(..) method. But it</div><div>is not. As a result we don&#39;t create a validation proxy and corresponding service</div><div>bean never performs any validation operations.  In case when any of the filtered</div><div>annotations is added to the impl bean things start to work (impl bean is processed).</div><div><br></div><div>The above case shows placement of annotation on a type level, but similar</div><div>behavior is observed in cases when annotation is on a method level.</div><div><br></div><div>As forcing presence of one of the annotations from the filter list on a impl</div><div>beans is not really an option, an alternative could be to drop the</div><div>@WithAnnotations filtering completely. Which is also not that great, as</div><div>dropping the filtering would mean that: </div><div><br></div><div>- Validation extension would need to process all possible beans that are available </div><div>- Such processing requires calls to Hibernate Validatior which must create the metadata</div><div>for each bean hierarchy and store it, even if nobody actually needs to validate those</div><div>beans. </div><div>- This would lead to much greater memory consumption as well as longer bootstrap </div><div>time. Which is not good.</div><div><br></div><div>Hence we would like to ask if there is any particular reasons why @WithAnnotations </div><div>filter does not consider looking at super classes and implemented interfaces to check </div><div>for annotations listed in @WithAnnotations?</div><div><br></div><div>Have a nice day,</div><div>Marko</div><div><br></div><div>[1] <a href="https://github.com/hibernate/hibernate-validator/blob/master/cdi/src/main/java/org/hibernate/validator/cdi/ValidationExtension.java#L222">https://github.com/hibernate/hibernate-validator/blob/master/cdi/src/main/java/org/hibernate/validator/cdi/ValidationExtension.java#L222</a></div></div>