浏览代码

HADOOP-14914. Change to a safely casting long to int. Contributed by Ajay Kumar.

Chen Liang 7 年之前
父节点
当前提交
46e18c8da7

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedBlockChecksumReconstructor.java

@@ -111,7 +111,7 @@ public class StripedBlockChecksumReconstructor extends StripedReconstructor {
     // case-1) length of data bytes which is fraction of bytesPerCRC
     // case-1) length of data bytes which is fraction of bytesPerCRC
     // case-2) length of data bytes which is less than bytesPerCRC
     // case-2) length of data bytes which is less than bytesPerCRC
     if (requestedLen <= toReconstructLen) {
     if (requestedLen <= toReconstructLen) {
-      int remainingLen = (int) requestedLen;
+      int remainingLen = Math.toIntExact(requestedLen);
       outputData = Arrays.copyOf(targetBuffer.array(), remainingLen);
       outputData = Arrays.copyOf(targetBuffer.array(), remainingLen);
 
 
       int partialLength = remainingLen % getChecksum().getBytesPerChecksum();
       int partialLength = remainingLen % getChecksum().getBytesPerChecksum();

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java

@@ -605,7 +605,7 @@ public class DirectoryCollection {
     if (totalSpace != 0) {
     if (totalSpace != 0) {
       long tmp = ((totalSpace - usableSpace) * 100) / totalSpace;
       long tmp = ((totalSpace - usableSpace) * 100) / totalSpace;
       if (Integer.MIN_VALUE < tmp && Integer.MAX_VALUE > tmp) {
       if (Integer.MIN_VALUE < tmp && Integer.MAX_VALUE > tmp) {
-        goodDirsDiskUtilizationPercentage = (int) tmp;
+        goodDirsDiskUtilizationPercentage = Math.toIntExact(tmp);
       }
       }
     } else {
     } else {
       // got no good dirs
       // got no good dirs

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/NodeManagerHardwareUtils.java

@@ -228,7 +228,7 @@ public class NodeManagerHardwareUtils {
           // on a single core machine - tmp can be between 0 and 1
           // on a single core machine - tmp can be between 0 and 1
           cores = 1;
           cores = 1;
         } else {
         } else {
-          cores = (int) tmp;
+          cores = Math.round(tmp);
         }
         }
       } else {
       } else {
         message = "Illegal value for "
         message = "Illegal value for "