Hi Emily,

you're right, methods of a subclass generated by Weld have the same annotations applied as the original class. This behavior is depended on by framework/extension authors therefore we cannot change that.

The BV spec / apache bean validation check seems too strict to me. The purpose of the constraint is to make sure that the postcondition constraints are not weaker in a subtype (e.g. a subtype could define @Valid with a strict subset of constraints in an overridden method). That sounds reasonable in general. In this particular case however, since Weld copies all the annotations, the constraint set is the same. The check could perhaps be altered to not fail if the constraint sets are equal.

Alternatively, the BV implementation would need to recognize that this is a Weld proxy and not fail on cascaded validation in such case.

Jozef

On 05/27/2015 01:12 AM, Emily Jiang wrote:
It seems Weld proxy has the same annotations as the proxied class. However this conflicts with Bean validation spec as far as @Valid is concerned.


This section of the bean validation spec is ending up in violation due to the duplicated annotation:
• One must not mark a method return value for cascaded validation more than once in a line of a class hierarchy.
In other words, overriding methods on sub types (be it sub classes/interfaces or interface implementations) cannot mark the return value for cascaded validation if the return value has already been marked on the overridden method of the super type or interface.

"The @Valid annotation is used to declare that a cascaded validation of the given method/constructor parameters or
return values is performed by the Bean Validation provider. "


Here is some debug added to the apache bean validation code that shows which two classes have the @Valid on the createValidEvent method:

$$$$$$$$$$$$DEBUG clazz = class org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarServiceWithCascadingReturnValue$Proxy$_$$_WeldSubclass method = public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarServiceWithCascadingReturnValue$Proxy$_$$_WeldSubclass.createValidEvent()
$$$$$$$$$$$$DEBUG clazz = class org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarServiceWithCascadingReturnValue method = public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarServiceWithCascadingReturnValue.createValidEvent()
$$$$$$$$$$$$$$$$$DEBUG returnValid = 2 // number of hits having @Valid

If I understand correctly, I think this annotation needs to be treated differently.
--
Thanks
Emily
=================
Emily Jiang
ejiang@apache.org


_______________________________________________
weld-dev mailing list
weld-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev