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

Change to a safely casting long to int.

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.1.0
    • 3.1.0
    • None
    • 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

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment