faces
faces copied to clipboard
BeanValidator should use EL-coerced value as bean property value
Discovered during https://github.com/eclipse-ee4j/mojarra/issues/5596
- have a
Byteproperty with@Min(1) - have a
<f:convertNumber>(just for formatting) - but NumberConverter returns Long
- this is usually EL-coerced during update model values phase, so no problem during usual Faces lifecycle
- but this Long is passed to BeanValidator#validateValue() during validations phase
- Hibernate Validator errors out with ClassCastException on Long -> Byte
This seems to have uncovered a potential bug in BeanValidator.
The BeanValidator#validate spec needs to be updated from
* <p> * Obtain a <code>jakarta.validation.BeanDescriptor</code> from the <code>jakarta.validation.Validator</code>. If * <code>hasConstraints()</code> on the <code>BeanDescriptor</code> returns false, take no action and return. Otherwise * proceed. * </p> * * <p> * Call {@link jakarta.validation.Validator#validateValue}, passing <em>valueBaseClass</em>, <em>valueProperty</em>, the * <em>value</em> argument, and <em>validatorGroupsArray</em> as arguments. * </p>
to
* <p> * Obtain a <code>jakarta.validation.BeanDescriptor</code> from the <code>jakarta.validation.Validator</code>. If * <code>hasConstraints()</code> on the <code>BeanDescriptor</code> returns false, take no action and return. Otherwise * proceed. * </p> * * <p class="changed_added_5_0"> * Obtain a <code>jakarta.el.ExpressionFactory</code> and use <code>coerceToType()</code> to coerce the * <em>value</em> argument to the type returned by <code>ValueExpression.getType()</code>. * </p> * * <p> * Call {@link jakarta.validation.Validator#validateValue}, passing <em>valueBaseClass</em>, <em>valueProperty</em>, the * <span class="changed_added_5_0">coerced</span> <em>value</em> argument, and <em>validatorGroupsArray</em> as arguments. * </p>