[hibernate-issues] [Hibernate-JIRA] Created: (BVAL-211) Consider making javax.validation.ValidatorContext a self-referential generic type

Gunnar Morling (JIRA) noreply at atlassian.com
Wed Feb 16 15:31:05 EST 2011


Consider making javax.validation.ValidatorContext a self-referential generic type
---------------------------------------------------------------------------------

                 Key: BVAL-211
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-211
             Project: Bean Validation
          Issue Type: Improvement
          Components: spec-general
    Affects Versions: 1.0 final
            Reporter: Gunnar Morling
            Priority: Minor


It should be investigated whether the interface javax.validation.ValidatorContext could be re-defined as self-referential generic type as follows:

{code:java}
public interface ValidatorContext <V extends ValidatorContext<V>> {

  V messageInterpolator(MessageInterpolator messageInterpolator);

  V traversableResolver(TraversableResolver traversableResolver);

  V constraintValidatorFactory(ConstraintValidatorFactory factory);

  Validator getValidator();
}
{code}

Provider-specific extensions of this interface (such as [HibernateValidatorContext|https://github.com/hibernate/hibernate-validator/blob/master/hibernate-validator/src/main/java/org/hibernate/validator/HibernateValidatorContext.java]) then wouldn't have to re-define all of ValidatorContext's methods returning their own type (which they currently must do in order to allow for the method chaining pattern to work correctly).

Generally this is a breaking change, as existing implementations wouldn't compile with the proposed new version of the interface. But as it is intended to be implemented by BV providers only, this seems acceptable. API users would get a raw type warning if they have variables of type ValidatorContext. This should happen very rarely though, as ValidatorContext typically is only used in chained method calls (with a final getValidator() invocation) but not assigned to a variable.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list