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

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

Github user zhuoliu commented on the pull request:

    https://github.com/apache/storm/pull/1023#issuecomment-172423672
  
    +1.
    The fix is necessary due to follows, which can cause problem during 
grouping.
    Integer.MAX_VALUE % 1 = 0
    Integer.MAX_VALUE % 2 = 0
    Integer.MAX_VALUE % 3 = -2
    Integer.MAX_VALUE % 4 = 0
    Integer.MAX_VALUE % 5 = -3
    Integer.MAX_VALUE % 6 = -2
    Integer.MAX_VALUE % 7 = -2
    Integer.MAX_VALUE % 8 = 0


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

Reply via email to