[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-423) @Min broken with BigInteger/BigDecimal

Dan Armak (JIRA) noreply at atlassian.com
Sat Aug 26 17:09:24 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-423?page=comments#action_24133 ] 

Dan Armak commented on ANN-423:
-------------------------------

I've attached a fix for MinValidator and MaxValidator, as well as code demonstrating the bug. However, RangeValidator cannot be fixed trivially.

If both min and max properties are used then, since they are of type long (as defined in @Range), a BigInteger is equivalent to a long anyway.

If, however, only min= or max= is used (functionally equivalent to @Min or @Max), the other parameter takes the value Long.MIN_VALUE or MAX_VALUE (default values defined in @Range). This means validation will be broken for BigIntegers that cannot be represented as longs, even if the sign bug is fixed. 

Worse, that default value is also set as a range constraint in the db, so if I have a bigger than 64bit numerical DB type I can't use @Range. (Is there such a type? I actually mapped by bigints as varchars in SQL Server 2000.) This behavior can be surprising. I suggest that either the default values should be changed to null (so that no check is made), or @Range is clearly documented not to work with BigIntegers and BigDecimals.

Of course, it would be best to make the @Min/@Max/@Range parameters BigIntegers themselves. But that would break BC, so it's up to you I guess.

> @Min broken with BigInteger/BigDecimal
> --------------------------------------
>
>          Key: ANN-423
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-423
>      Project: Hibernate Annotations
>         Type: Bug

>   Components: validator
>     Versions: 3.2.0.cr1
>  Environment: Hibernate 3.2.0cr2
>     Reporter: Dan Armak
>     Priority: Minor
>  Attachments: Test.java, Validator.diff
>
>
> MinValidator supports properties of type BigInteger and BigDecimal by coding against Number.longValue(). However, in BigInteger and BigDecimal, longValue() returns the lower 64 bits, which can flip the apparent sign for a BigInteger > Long.MAX_VALUE or < Long.MIN_VALUE. In these cases, @Min or @Max validation (respectively) will fail.

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