hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yufei Gu (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HADOOP-14914) Change to a safely casting long to int.
Date Fri, 29 Sep 2017 00:26:00 GMT
Yufei Gu created HADOOP-14914:

             Summary: Change to a safely casting long to int. 
                 Key: HADOOP-14914
                 URL: https://issues.apache.org/jira/browse/HADOOP-14914
             Project: Hadoop Common
          Issue Type: Improvement
    Affects Versions: 3.1.0
            Reporter: Yufei Gu

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. 

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org

View raw message