[hibernate-issues] [Hibernate-JIRA] Commented: (HV-23) NotEmptyValidator throws ClassCastException on non-null wrapper types

scott leberknight (JIRA) noreply at atlassian.com
Fri May 25 23:11:04 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HV-23?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_27057 ] 

scott leberknight commented on HV-23:
-------------------------------------

I realize the JavaDocs say this validator is meant for Collections, arrays, and Strings and so it might not be meant for things other than these types. But since @NotNull checks the null constraints in the DB before processing other validators and throws a PropertyValueException in case of a null instead of giving you an InvalidStateException, it seems @NotEmpty would be a nice alternative when you want to essentially verify that a required field is present. I wrote my own @Required validator but would obviously prefer a standard Hibernate one. Thanks.

> NotEmptyValidator throws ClassCastException on non-null wrapper types
> ---------------------------------------------------------------------
>
>                 Key: HV-23
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-23
>             Project: Hibernate Validator
>          Issue Type: Bug
>          Components: validators
>    Affects Versions: Bundle 3.2.1, 3.0.0.ga
>            Reporter: scott leberknight
>         Attachments: NotEmptyValidatorClassCastExceptionBugTest.java
>
>
> The NotEmptyValidator.isValid() method throws a ClassCastException if a non-null primitive wrapper type (e.g. Long) is supplied as the argument. The method assumes that if the value is not null, is not an array, collection, or map, that it can be cast to a String, which it cannot for primitive wrappers. See attached JUnit test, which also contains a possible fix to the logic and has a test for the fix too. I put the file in the org.hibernate.validator package so it can be dropped in as-is to the Hibernate Validator codebase.

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