[hibernate-issues] [Hibernate-JIRA] Updated: (HV-421) Reconsider behavior of parameter validation for inheritance hierarchies

Gunnar Morling (JIRA) noreply at atlassian.com
Mon Jan 17 17:27:05 EST 2011


     [ http://opensource.atlassian.com/projects/hibernate/browse/HV-421?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gunnar Morling updated HV-421:
------------------------------

    Description: 
Let A extend B and A#foo() override B#foo(). When validating an invocation of A#foo() the current implementation will evaluate all parameter constraints defined at A#foo() *and* B#foo(). That way foo()'s preconditions defined in B are strengthened by A. 

According to the ["Programming by contract"|http://en.wikipedia.org/wiki/Programming_by_contract] article on WP this is not allowed, subtypes may only weaken preconditions defined by supertypes. The common implementation pattern for this is to combine the preconditions within a hierarchy by a logical OR, meaning the weakest precondition in the hierarchy applies.

Note that postconditions (return value constraints) may be strengthened (but not weakened) by subtypes. Therefore the current implementation (AND combination) should be correct here.


  was:
Let A extend B and A#foo() override B#foo(). When validating an invocation of A#foo() the current implementation will evaluate all parameter constraints defined at A#foo() *and* B#foo(). That way the foo()'s preconditions defined in B are strengthened by A. 

According to the ["Programming by contract"|http://en.wikipedia.org/wiki/Programming_by_contract] article on WP this is not allowed, subtypes may only weaken preconditions defined by supertypes. The common implementation pattern for this is to combine the preconditions within a hierarchy by a logical OR, meaning the weakest precondition in the hierarchy applies.

Note that postconditions (return value constraints) may be strengthened (but not weakened) by subtypes. Therefore the current implementation (AND combination) should be correct here.



> Reconsider behavior of parameter validation for inheritance hierarchies
> -----------------------------------------------------------------------
>
>                 Key: HV-421
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-421
>             Project: Hibernate Validator
>          Issue Type: Bug
>          Components: engine
>            Reporter: Gunnar Morling
>             Fix For: 4.2.0.Beta2
>
>
> Let A extend B and A#foo() override B#foo(). When validating an invocation of A#foo() the current implementation will evaluate all parameter constraints defined at A#foo() *and* B#foo(). That way foo()'s preconditions defined in B are strengthened by A. 
> According to the ["Programming by contract"|http://en.wikipedia.org/wiki/Programming_by_contract] article on WP this is not allowed, subtypes may only weaken preconditions defined by supertypes. The common implementation pattern for this is to combine the preconditions within a hierarchy by a logical OR, meaning the weakest precondition in the hierarchy applies.
> Note that postconditions (return value constraints) may be strengthened (but not weakened) by subtypes. Therefore the current implementation (AND combination) should be correct here.

-- 
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