hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hudson (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HADOOP-14914) Change to a safely casting long to int.
Date Wed, 13 Dec 2017 23:19:00 GMT

    [ https://issues.apache.org/jira/browse/HADOOP-14914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16290075#comment-16290075
] 

Hudson commented on HADOOP-14914:
---------------------------------

SUCCESS: Integrated in Jenkins build Hadoop-trunk-Commit #13370 (See [https://builds.apache.org/job/Hadoop-trunk-Commit/13370/])
HADOOP-14914. Change to a safely casting long to int. Contributed by (cliang: rev 46e18c8da76ea8d91a16e59ba1154c30f37cb9fd)
* (edit) hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/NodeManagerHardwareUtils.java
* (edit) hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedBlockChecksumReconstructor.java
* (edit) hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java


> 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
>            Assignee: Ajay Kumar
>             Fix For: 3.1.0
>
>         Attachments: HADOOP-14914.001.patch, HADOOP-14914.002.patch
>
>
> There are bunches of casting long to int like this:
> {code}
> long l = 123
> int i = (int) l;
> {code}
> 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
(v6.4.14#64029)

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


Mime
View raw message