Uploaded image for project: 'Apache Storm'
  1. Apache Storm
  2. STORM-1481

avoid Math.abs(Integer) get a negative value

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0, 0.10.1, 2.0.0
    • Component/s: storm-core
    • Labels:
      None

      Description

      before fix:

      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;
              }
          }
      

      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:

          public static int toPositive(int number) {
              return number & Integer.MAX_VALUE;
          }
      

        Attachments

          Activity

            People

            • Assignee:
              vesense Xin Wang
              Reporter:
              vesense Xin Wang
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: