Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-14914

Change to a safely casting long to int.

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.0
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      There are bunches of casting long to int like this:

      long l = 123
      int i = (int) l;
      

      This is not a safe cast. if l is greater than Integer.MAX_VALUE, i would be negative, which is an unexpected behavior. We probably at least want to throw an exception in that case. I suggest to use Math.toIntExact(longValue) to replace them, which throws an exception if the value overflows an int.

        Attachments

        1. HADOOP-14914.001.patch
          7 kB
          Ajay Kumar
        2. HADOOP-14914.002.patch
          3 kB
          Ajay Kumar

          Activity

            People

            • Assignee:
              ajayydv Ajay Kumar
              Reporter:
              yufeigu Yufei Gu
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: