[jira] [Created] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
Sebb created MATH-793:
-------------------------

             Summary: OrderedTuple#hashCode() uses casting instead of boxing
                 Key: MATH-793
                 URL: https://issues.apache.org/jira/browse/MATH-793
             Project: Commons Math
          Issue Type: Bug
         Environment: OrderedTuple#hashCode() is as follows:

{code}
public int hashCode() {
    return Arrays.hashCode(components)   ^
           ((Integer) offset).hashCode() ^
           ((Integer) lsb).hashCode()    ^
           ((Boolean) posInf).hashCode() ^
           ((Boolean) negInf).hashCode() ^
           ((Boolean) nan).hashCode();
}
{code}

This is not the correct way to convert primitives to their object equivalents.

((Integer) x).hashCode() == x
Boolean#hashCode() is defined as

value ? 1231 : 1237

Note that this error won't be found unless the compiler emits warnings for boxing.
            Reporter: Sebb




--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)

     [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe resolved MATH-793.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 3.1

Fixed in subversion repository as of r1343616.

Thanks for reporting the issue.
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

     [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated MATH-793:
----------------------

    Environment:
OrderedTuple#hashCode() is as follows:

{code}
public int hashCode() {
    return Arrays.hashCode(components)   ^
           ((Integer) offset).hashCode() ^
           ((Integer) lsb).hashCode()    ^
           ((Boolean) posInf).hashCode() ^
           ((Boolean) negInf).hashCode() ^
           ((Boolean) nan).hashCode();
}
{code}

This is not the correct way to convert primitives to their object equivalents.

{code}
((Integer) x).hashCode() == x

Boolean#hashCode() is defined as

value ? 1231 : 1237
{code}

Note that this error won't be found unless the compiler emits warnings for boxing.

  was:
OrderedTuple#hashCode() is as follows:

{code}
public int hashCode() {
    return Arrays.hashCode(components)   ^
           ((Integer) offset).hashCode() ^
           ((Integer) lsb).hashCode()    ^
           ((Boolean) posInf).hashCode() ^
           ((Boolean) negInf).hashCode() ^
           ((Boolean) nan).hashCode();
}
{code}

This is not the correct way to convert primitives to their object equivalents.

((Integer) x).hashCode() == x
Boolean#hashCode() is defined as

value ? 1231 : 1237

Note that this error won't be found unless the compiler emits warnings for boxing.

   

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

    [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13285012#comment-13285012 ]

Luc Maisonobe commented on MATH-793:
------------------------------------

Another fix has been committed as of r1343920, using inline computation.
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Reopened] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

     [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb reopened MATH-793:
-----------------------


The hash code calculation added in r1343920 is a bit strange.

The way it is normally done is as follows:

{code}
int oddMult = 37; // constant odd multiplier
int hashCode = 17; // seed (odd)

hashCode = hashCode * oddMult + field1.hashcode;
hashCode = hashCode * oddMult + field2.hashcode;
{code}
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

    [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13285062#comment-13285062 ]

Luc Maisonobe commented on MATH-793:
------------------------------------

OK. Perhaps should we even use prime numbers instead of simply odd numbers ?
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

    [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13285082#comment-13285082 ]

Gilles commented on MATH-793:
-----------------------------

There is also an example in the "Pair" class (package "util"). That one has been changed recently as the previous code was certainly not good, but I don't guarantee it to be the best choice ;).
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

    [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13285526#comment-13285526 ]

Luc Maisonobe commented on MATH-793:
------------------------------------

Another attempt to compute hash has been committed as of r1344166.

Sebb, I let you decide if the issue is solved or not and set the status accordingly.
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

    [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13286537#comment-13286537 ]

Luc Maisonobe commented on MATH-793:
------------------------------------

Can we set this to fixed?
               

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (MATH-793) OrderedTuple#hashCode() uses casting instead of boxing

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

     [ https://issues.apache.org/jira/browse/MATH-793?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved MATH-793.
-----------------------

    Resolution: Fixed
   

> OrderedTuple#hashCode() uses casting instead of boxing
> ------------------------------------------------------
>
>                 Key: MATH-793
>                 URL: https://issues.apache.org/jira/browse/MATH-793
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: OrderedTuple#hashCode() is as follows:
> {code}
> public int hashCode() {
>     return Arrays.hashCode(components)   ^
>            ((Integer) offset).hashCode() ^
>            ((Integer) lsb).hashCode()    ^
>            ((Boolean) posInf).hashCode() ^
>            ((Boolean) negInf).hashCode() ^
>            ((Boolean) nan).hashCode();
> }
> {code}
> This is not the correct way to convert primitives to their object equivalents.
> {code}
> ((Integer) x).hashCode() == x
> Boolean#hashCode() is defined as
> value ? 1231 : 1237
> {code}
> Note that this error won't be found unless the compiler emits warnings for boxing.
>            Reporter: Sebb
>             Fix For: 3.1
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira