You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/01/16 13:02:39 UTC

[jira] [Commented] (STORM-1481) avoid Math.abs(Integer) get a negative value

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

ASF GitHub Bot commented on STORM-1481:
---------------------------------------

GitHub user vesense opened a pull request:

    https://github.com/apache/storm/pull/1023

    [STORM-1481] avoid Math.abs(Integer) get a negative value

    https://issues.apache.org/jira/browse/STORM-1481

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/vesense/storm STORM-1481

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/storm/pull/1023.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1023
    
----
commit 181b3b09a973acf99719ad60fe03f4d23c869324
Author: Xin Wang <be...@163.com>
Date:   2016-01-16T11:40:24Z

    avoid abs get negative value

----


> avoid Math.abs(Integer) get a negative value
> --------------------------------------------
>
>                 Key: STORM-1481
>                 URL: https://issues.apache.org/jira/browse/STORM-1481
>             Project: Apache Storm
>          Issue Type: Bug
>          Components: storm-core
>            Reporter: Xin Wang
>            Assignee: Xin Wang
>
> before fix:
> {code:title=org.apache.storm.trident.partition.IndexHashGrouping}
>     public static int objectToIndex(Object val, int numPartitions) {
>         if(val==null) return 0;
>         else {
>             return Math.abs(val.hashCode()) % numPartitions;
>         }
>     }
> {code}
> If the hashcode is Integer.MIN_VALUE, then the result will be negative as well (since Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE). 
> after fix:
> Use toPositive replace Math.abs:
> {code}
>     public static int toPositive(int number) {
>         return number & Integer.MAX_VALUE;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)