[hibernate-issues] [Hibernate-JIRA] Created: (HV-53) AssertTrue and AssertFalse not compatible with null values

benoit heinrich (JIRA) noreply at atlassian.com
Thu May 1 05:31:33 EDT 2008


AssertTrue and AssertFalse not compatible with null values
----------------------------------------------------------

                 Key: HV-53
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-53
             Project: Hibernate Validator
          Issue Type: Bug
          Components: validators
    Affects Versions: 3.0.0.ga
            Reporter: benoit heinrich


The AssertTrue and AssertFalse validators do not work with null values, they actually generate a NullPointerException.

The code fix for this should be:

public class AssertFalseValidator implements Validator<AssertFalse>, Serializable {

        public boolean isValid(Object value) {
                if (value == null) return true;  << this is the fix
                return !(Boolean) value;
        }

        public void initialize(AssertFalse parameters) {
        }

}


public class AssertTrueValidator implements Validator<AssertTrue>, Serializable {

        public boolean isValid(Object value) {
                if (value == null) return true;  << this is the fix
                return (Boolean) value;
        }

        public void initialize(AssertTrue parameters) {
        }

}



Cheers,
/Benoit

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