You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by "Daniel Weidele (JIRA)" <em...@incubator.apache.org> on 2012/10/02 11:03:07 UTC

[jira] [Created] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Daniel Weidele created EMPIREDB-171:
---------------------------------------

             Summary: ObjectUtils.compareEquals fails on BigDecimal
                 Key: EMPIREDB-171
                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
             Project: Empire-DB
          Issue Type: Bug
          Components: Core
    Affects Versions: empire-db-2.4.0
            Reporter: Daniel Weidele
            Priority: Critical


Observed:
When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.

Expected:
ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Posted by "Francis De Brabandere (JIRA)" <em...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/EMPIREDB-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467611#comment-13467611 ] 

Francis De Brabandere commented on EMPIREDB-171:
------------------------------------------------

hmm, not sure this is a good idea...
                
> ObjectUtils.compareEquals fails on BigDecimal
> ---------------------------------------------
>
>                 Key: EMPIREDB-171
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.0
>            Reporter: Daniel Weidele
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Observed:
> When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.
> Expected:
> ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Posted by "Rainer Döbele (JIRA)" <em...@incubator.apache.org>.
     [ https://issues.apache.org/jira/browse/EMPIREDB-171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rainer Döbele updated EMPIREDB-171:
-----------------------------------

    Fix Version/s: empire-db-2.4.1
    
> ObjectUtils.compareEquals fails on BigDecimal
> ---------------------------------------------
>
>                 Key: EMPIREDB-171
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.0
>            Reporter: Daniel Weidele
>            Priority: Critical
>             Fix For: empire-db-2.4.1
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Observed:
> When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.
> Expected:
> ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Posted by "Rainer Döbele (JIRA)" <em...@incubator.apache.org>.
     [ https://issues.apache.org/jira/browse/EMPIREDB-171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rainer Döbele resolved EMPIREDB-171.
------------------------------------

    Resolution: Fixed

added check for Comaprable interface and use of compareTo rather than equals.
                
> ObjectUtils.compareEquals fails on BigDecimal
> ---------------------------------------------
>
>                 Key: EMPIREDB-171
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.0
>            Reporter: Daniel Weidele
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Observed:
> When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.
> Expected:
> ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Posted by "Rainer Döbele (JIRA)" <em...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/EMPIREDB-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467916#comment-13467916 ] 

Rainer Döbele commented on EMPIREDB-171:
----------------------------------------

In math I would have failed if I had agrued that 2.0 is not equal to 2.00. I really wonder who came up with that idea to implment the equals method for BigDecimals that way.
But let's review the facts: 2 Methods (compareTo and equals) that someone would normaly assume to behave in the same way, behave differently.
Now our method is called compareEqual().
Hence we must decide whether we want the compare logic or the equals logic.
And since the function tries to match values even of different data types, it is obvious for me that for BigDecimals we need the compare logic.

                
> ObjectUtils.compareEquals fails on BigDecimal
> ---------------------------------------------
>
>                 Key: EMPIREDB-171
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.0
>            Reporter: Daniel Weidele
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Observed:
> When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.
> Expected:
> ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Posted by "Francis De Brabandere (JIRA)" <em...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/EMPIREDB-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467626#comment-13467626 ] 

Francis De Brabandere commented on EMPIREDB-171:
------------------------------------------------

I wonder if there are any cases where compareTo would result in unexpected behaviour...

This is the javadoc for the equals() method
Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).
                
> ObjectUtils.compareEquals fails on BigDecimal
> ---------------------------------------------
>
>                 Key: EMPIREDB-171
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.0
>            Reporter: Daniel Weidele
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Observed:
> When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.
> Expected:
> ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (EMPIREDB-171) ObjectUtils.compareEquals fails on BigDecimal

Posted by "Rainer Döbele (JIRA)" <em...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/EMPIREDB-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13467619#comment-13467619 ] 

Rainer Döbele commented on EMPIREDB-171:
----------------------------------------

I have had a look at this and Daniel is right.
The intention of that method is to check whether two values are equal. It will even return true even if types don't match and e.g. one is a string and the other a number but both represent the same value.
In this case both values are of type BigDecimal and both have a value of 50.
To my own suprise BigDecimal.equal() returns false although everybody knows that 50 and 50.00 are two representations of the same value.
I think this is a bug in Java.
BigDecimal.compareTo() however works.
I would suggest to check for the comparable interface and use that method instead of equals()
(I'll probably fix this and I'll check it in later)

                
> ObjectUtils.compareEquals fails on BigDecimal
> ---------------------------------------------
>
>                 Key: EMPIREDB-171
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-171
>             Project: Empire-DB
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: empire-db-2.4.0
>            Reporter: Daniel Weidele
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Observed:
> When comparing a BigDecimal with internal value e.g. '50' to another BigDecimal with internal value '50.00' ObjectUtils.compareEquals returns false as it internally forwards to the BigDecimal.equals method, which also relies on internal BigDecimal properties such as scale, etc.
> Expected:
> ObjectUtils.compareEquals should return true when comparing e.g. '50' to '50.00'

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira