You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by "P. Taylor Goetz (JIRA)" <ji...@apache.org> on 2016/01/20 21:47:40 UTC

[jira] [Updated] (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:all-tabpanel ]

P. Taylor Goetz updated STORM-1481:
-----------------------------------
    Fix Version/s: 0.10.1

> 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
>             Fix For: 1.0.0, 0.10.1, 2.0.0
>
>
> 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)