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

This commit is contained in:
Chen Liang 2017-12-13 14:56:14 -08:00
parent d447152d49
commit 46e18c8da7
3 changed files with 3 additions and 3 deletions

View File

@ -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();

View File

@ -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

View File

@ -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 "