<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I spent a long time scrutinizing the spec for exception cases. This email list exceptional cases and propose to associate specific exceptions to them or not. Please review and tell me:</div><div> - if you think I forgot cases that needs additional consideration.</div><div> - which model you favor (see B)</div><div><br></div><div><br></div><div><b>A. EXCEPTION CASES</b></div><div><b><br></b></div><div>I described the error cases and a fine grained Exception model (see B) and have a few questions see ???</div><div><b><br></b></div><div><b>1. Error report</b></div><div><br></div><div>Use for other frameworks to report violation reports</div><div><br></div><div><div>**</div><div> * Report the result of constraint violations</div><div> *</div><div> * @author Emmanuel Bernard</div><div> */</div><div>public class ConstraintViolationException extends ValidationException {</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>private final Set<ConstraintViolation> constraintViolations;</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>/**</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * Creates a constraint violation report</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> *</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * @param message error message</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * @param constraintViolations Set of ConstraintViolation</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> */</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>public ConstraintViolationException(String message, Set<ConstraintViolation> constraintViolations) {</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>super( message );</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>this.constraintViolations = constraintViolations;</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>/**</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * Creates a constraint violation report</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> *</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * @param constraintViolations Set of ConstraintViolation</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> */</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>public ConstraintViolationException(Set<ConstraintViolation> constraintViolations) {</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>super();</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>this.constraintViolations = constraintViolations;</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>/**</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * Set of constraint violations reported during a validation</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> *</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> * @return Set of CosntraintViolation</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span> */</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>public Set<ConstraintViolation> getConstraintViolations() {</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>return constraintViolations;</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>}</div><div>}</div></div><div><br></div><div><b>2. Execution exceptions</b></div><div><br></div><div>ie during validator.validate(...);</div><div><br></div><div><br></div><div><i>Constraint Declaration</i></div><div>These can be found a compilation time with an annotation processor or an IDE</div><div>??? <span class="Apple-style-span" style="font-style: italic; ">UnsupportedTypeException </span>or should it be<span class="Apple-style-span" style="font-style: italic; "> AmbiguousConstraintUsageException</span></div><div> More than one ConstraintValidator targeting the same type</div><div><div> declared property type property has too many matches</div></div><div><i> UnsupportedTypeException</i> </div><div> declared property type property has no match</div><div> <i>ConstraintDefinitionException</i></div><div> composition parameter overriding (name, composing constraint or incompatible parameter types)</div><div> constraint composed of itself</div><div><br></div><div> </div><div><i>Constraint implementation</i></div><div> <i>ConstraintInitializationException</i></div><div>??? initialize() must raise a RTE will be wrapped OR should we not wrap</div><div> <span class="Apple-style-span" style="font-style: italic; ">UnsupportedTypeException</span></div><div> isValid incompatible type (detected by impl) => same as "declared property type property has no match"</div><div><i> ConstraintExcecutionException</i></div><div> isValid throws a RTE will be wrapped into ConstraintValidatorExecutionException</div><div><i> ConstraintCreationException</i></div><div> ConstraintValidatorFactory fails with RTE. Wraps it.</div><div><br></div><div>??? should we collapse that into a <i>ConstraintExecutionException</i> or even <i>ValidationException</i></div><div><br></div><div><div><i>Groups</i></div><div> Can be checked at built time by an IDE or an AnnotationProcessor</div><div><i> GroupDefinitionException</i></div><div> cyclic dependency between groups sequences and group inheritance</div><div> missing group X on a Default group overriding</div><div> Group sequence name used in a constraint declaration</div><div> group is not an interface</div></div><div> </div><div><i>Various</i></div><div> <i>IllegalArgumentException</i> </div><div> if object to validate is null, or empty set?</div><div>??? Calls to SPi like MessageInterpolator / TraversableResolver should be wrapped?</div><div> </div><div><br></div><div><b>3. Bootstrap</b></div><div><br></div><div><i>ProviderNotFoundException</i> </div><div> cannot find matching provider</div><div> cannot find any provider</div><div><br></div><div><i>ConfigurationException</i></div><div> cannot read XML cong</div><div> more than one XML conf</div><div> no no-arg constructor on classes described by XML</div><div><br></div><div><i>MappingException</i></div><div> cannot read XML mapping</div><div> entity described more than once</div><div> field/getter described more than once</div><div> Wrong class / field / getter name</div><div> Wrong constraint declaration</div><div> Wrong constraint definition</div><div><br></div><div> </div><div><b>B. EXCEPTION MODEL</b></div><div><br></div><div>We have three approaches:</div><div><br></div><div>1. specialize an exception when the application can do something about it</div><div>In this case all exceptions are <i>ValidationException</i> except <i>ConstraintViolationException</i></div><div><br></div><div>2. specialize exceptions to provide informations to the user</div><div><i>ValidationException</i> (root)</div><div><i>ConstraintViolationException</i></div><div><i>AmbiguousConstraintUsageException</i></div><div><i>UnsupportedTypeException</i></div><div><i>ConstraintDefinitionException</i></div><div><i>ConstraintInitializationException</i></div><div><i><span class="Apple-style-span" style="font-style: normal; "><div><span class="Apple-style-span" style="font-style: italic; ">ConstraintExcecutionException</span></div><div><span class="Apple-style-span" style="font-style: italic; ">ConstraintCreationException</span></div></span></i></div><div><span class="Apple-style-span" style="font-style: italic; ">GroupDefinitionException</span></div><div><span class="Apple-style-span" style="font-style: italic; ">ProviderNotFoundException</span></div><div><span class="Apple-style-span" style="font-style: italic; ">ConfigurationException</span></div><div><span class="Apple-style-span" style="font-style: italic; ">MappingException</span></div><div><i><br></i></div><div>3. a man in the middle approach with some exception collapsing</div><div><br></div><div><div><i>ValidationException</i> (root)</div><div><i>ConstraintViolationException</i></div><div><i>ConstraintDeclarationException (instead of UnsupportedTypeException and AmbiguousConstraintUsageException)</i></div><div><i>ConstraintDefinitionException</i></div><div><span class="Apple-style-span" style="font-style: italic; ">ConstraintExcecutionException</span></div><div><i><span class="Apple-style-span" style="font-style: normal; "><div><span class="Apple-style-span" style="font-style: italic; ">GroupDefinitionException</span></div></span></i></div><div><span class="Apple-style-span" style="font-style: italic; ">ConfigurationException</span></div><div><i><br></i></div><div> </div></div><div> </div><div><br></div></div></body></html>