HADOOP-13663 Index out of range in SysInfoWindows. Contributed by Inigo Goiri

This commit is contained in:
Steve Loughran 2016-09-29 11:35:00 +01:00
parent 1f1e47e411
commit 2b6b4fd779
2 changed files with 37 additions and 28 deletions

View File

@ -100,8 +100,9 @@ public class SysInfoWindows extends SysInfo {
String sysInfoStr = getSystemInfoInfoFromShell();
if (sysInfoStr != null) {
final int sysInfoSplitCount = 11;
String[] sysInfo = sysInfoStr.substring(0, sysInfoStr.indexOf("\r\n"))
.split(",");
int index = sysInfoStr.indexOf("\r\n");
if (index >= 0) {
String[] sysInfo = sysInfoStr.substring(0, index).split(",");
if (sysInfo.length == sysInfoSplitCount) {
try {
vmemSize = Long.parseLong(sysInfo[0]);
@ -131,6 +132,9 @@ public class SysInfoWindows extends SysInfo {
LOG.warn("Expected split length of sysInfo to be "
+ sysInfoSplitCount + ". Got " + sysInfo.length);
}
} else {
LOG.warn("Wrong output from sysInfo: " + sysInfoStr);
}
}
}
}

View File

@ -141,10 +141,15 @@ public class TestSysInfoWindows {
@Test(timeout = 10000)
public void errorInGetSystemInfo() {
SysInfoWindowsMock tester = new SysInfoWindowsMock();
// info str derived from windows shell command has \r\n termination
// info str derived from windows shell command is null
tester.setSysinfoString(null);
// call a method to refresh values
tester.getAvailablePhysicalMemorySize();
// info str derived from windows shell command with no \r\n termination
tester.setSysinfoString("");
// call a method to refresh values
tester.getAvailablePhysicalMemorySize();
}
}