Xin Wang created STORM-1481:
-------------------------------
Summary: 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)