Fixed few coverity issues like invalid boxing unboxing issues, resource leaks, null dereferences

This commit is contained in:
Santhosh Edukulla 2014-11-13 17:25:26 +05:30
parent fc4dceaa99
commit ef6ec7b276
10 changed files with 63 additions and 56 deletions

View File

@ -179,7 +179,7 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F
@Override @Override
public Integer getSourcePortStart() { public Integer getSourcePortStart() {
if (publicStartPort != null) { if (publicStartPort != null) {
return publicStartPort.intValue(); return publicStartPort;
} }
return null; return null;
} }
@ -188,12 +188,11 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F
public Integer getSourcePortEnd() { public Integer getSourcePortEnd() {
if (publicEndPort == null) { if (publicEndPort == null) {
if (publicStartPort != null) { if (publicStartPort != null) {
return publicStartPort.intValue(); return publicStartPort;
} }
} else { } else {
return publicEndPort.intValue(); return publicEndPort;
} }
return null; return null;
} }

View File

@ -115,8 +115,11 @@ public class DeleteEgressFirewallRuleCmd extends BaseAsyncCmd {
@Override @Override
public Long getSyncObjId() { public Long getSyncObjId() {
return _firewallService.getFirewallRule(id).getNetworkId(); FirewallRule fw = _firewallService.getFirewallRule(id);
} if (fw != null)
return fw.getNetworkId();
return null;
}
@Override @Override
public ApiCommandJobType getInstanceType() { public ApiCommandJobType getInstanceType() {

View File

@ -47,15 +47,10 @@ public class AddIpToVmNicTest extends TestCase {
private ResponseGenerator responseGenerator; private ResponseGenerator responseGenerator;
private SuccessResponse successResponseGenerator; private SuccessResponse successResponseGenerator;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Override @Override
@Before @Before
public void setUp() { public void setUp() {
addIpToVmNicCmd = new AddIpToVmNicCmd() {
};
removeIpFromVmNicCmd = new RemoveIpFromVmNicCmd();
} }
@Test @Test
@ -108,8 +103,6 @@ public class AddIpToVmNicTest extends TestCase {
Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(true); Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(true);
removeIpFromNic._networkService = networkService; removeIpFromNic._networkService = networkService;
successResponseGenerator = Mockito.mock(SuccessResponse.class);
removeIpFromNic.execute(); removeIpFromNic.execute();
} }

View File

@ -497,17 +497,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
throw new CloudRuntimeException("Unable to resolve " + ip); throw new CloudRuntimeException("Unable to resolve " + ip);
} }
try { try (SocketChannel ch1 = SocketChannel.open(new InetSocketAddress(addr, Port.value()));){
ch = SocketChannel.open(new InetSocketAddress(addr, Port.value())); ch1.configureBlocking(true); // make sure we are working at blocking mode
ch.configureBlocking(true); // make sure we are working at blocking mode ch1.socket().setKeepAlive(true);
ch.socket().setKeepAlive(true); ch1.socket().setSoTimeout(60 * 1000);
ch.socket().setSoTimeout(60 * 1000);
try { try {
SSLContext sslContext = Link.initSSLContext(true); SSLContext sslContext = Link.initSSLContext(true);
sslEngine = sslContext.createSSLEngine(ip, Port.value()); sslEngine = sslContext.createSSLEngine(ip, Port.value());
sslEngine.setUseClientMode(true); sslEngine.setUseClientMode(true);
Link.doHandshake(ch, sslEngine, true); Link.doHandshake(ch1, sslEngine, true);
s_logger.info("SSL: Handshake done"); s_logger.info("SSL: Handshake done");
} catch (Exception e) { } catch (Exception e) {
throw new IOException("SSL: Fail to init SSL! " + e); throw new IOException("SSL: Fail to init SSL! " + e);

View File

@ -336,9 +336,10 @@ public class VmwareStorageProcessor implements StorageProcessor {
TemplateObjectTO newTemplate = new TemplateObjectTO(); TemplateObjectTO newTemplate = new TemplateObjectTO();
if (managed) { if (managed) {
String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk"); if(dsMo != null) {
String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk");
newTemplate.setPath(path); newTemplate.setPath(path);
}
} }
else { else {
newTemplate.setPath(templateUuidName); newTemplate.setPath(templateUuidName);

View File

@ -191,16 +191,18 @@ public class JuniperSrxResource implements ServerResource {
throw new Exception("Failed to find Juniper SRX XML file: " + filename); throw new Exception("Failed to find Juniper SRX XML file: " + filename);
} }
FileReader fr = new FileReader(xmlFilePath); try(FileReader fr = new FileReader(xmlFilePath);
BufferedReader br = new BufferedReader(fr); BufferedReader br = new BufferedReader(fr);) {
String xml = "";
String xml = ""; String line;
String line; while ((line = br.readLine()) != null) {
while ((line = br.readLine()) != null) { xml += line.trim();
xml += line.trim(); }
return xml;
}catch (Exception e) {
s_logger.debug(e);
return null;
} }
return xml;
} catch (Exception e) { } catch (Exception e) {
s_logger.debug(e); s_logger.debug(e);
return null; return null;

View File

@ -401,12 +401,14 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
// Map<String, Collection<String>> parameterMap = paramMultiMap.asMap(); // Map<String, Collection<String>> parameterMap = paramMultiMap.asMap();
final Map parameterMap = new HashMap<String, String[]>(); final Map parameterMap = new HashMap<String, String[]>();
String responseType = HttpUtils.RESPONSE_TYPE_XML; String responseType = HttpUtils.RESPONSE_TYPE_XML;
for (final NameValuePair param : paramList) { if(paramList != null) {
if (param.getName().equalsIgnoreCase("response")) { for (final NameValuePair param : paramList) {
responseType = param.getValue(); if (param.getName().equalsIgnoreCase("response")) {
continue; responseType = param.getValue();
continue;
}
parameterMap.put(param.getName(), new String[]{param.getValue()});
} }
parameterMap.put(param.getName(), new String[] {param.getValue()});
} }
// Get the type of http method being used. // Get the type of http method being used.

View File

@ -265,18 +265,20 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
"] is down." + "] is down." +
((sb != null) ? sb.toString() : "")); ((sb != null) ? sb.toString() : ""));
for (VMInstanceVO vm : vms) { if (vms != null) {
if (s_logger.isDebugEnabled()) { for (VMInstanceVO vm : vms) {
s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName()); if (s_logger.isDebugEnabled()) {
s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName());
}
vm = _instanceDao.findByUuid(vm.getUuid());
Long hostId = vm.getHostId();
if (hostId != null && !hostId.equals(host.getId())) {
s_logger.debug("VM " + vm.getInstanceName() + " is not on down host " + host.getId() + " it is on other host "
+ hostId + " VM HA is done");
continue;
}
scheduleRestart(vm, investigate);
} }
vm = _instanceDao.findByUuid(vm.getUuid());
Long hostId = vm.getHostId();
if ( hostId != null && !hostId.equals(host.getId()) ) {
s_logger.debug("VM " + vm.getInstanceName() + " is not on down host " + host.getId() + " it is on other host "
+ hostId + " VM HA is done");
continue;
}
scheduleRestart(vm, investigate);
} }
} }

View File

@ -1632,12 +1632,14 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
try { try {
clusterId = Long.valueOf(cluster); clusterId = Long.valueOf(cluster);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
ClusterVO c = _clusterDao.findBy(cluster, podId); if (podId != null) {
if (c == null) { ClusterVO c = _clusterDao.findBy(cluster, podId.longValue());
c = new ClusterVO(dcId, podId, cluster); if (c == null) {
c = _clusterDao.persist(c); c = new ClusterVO(dcId, podId.longValue(), cluster);
c = _clusterDao.persist(c);
}
clusterId = c.getId();
} }
clusterId = c.getId();
} }
} }

View File

@ -1317,11 +1317,15 @@ public class NetUtils {
BigInteger startInt = convertIPv6AddressToBigInteger(start); BigInteger startInt = convertIPv6AddressToBigInteger(start);
BigInteger endInt = convertIPv6AddressToBigInteger(end); BigInteger endInt = convertIPv6AddressToBigInteger(end);
if (endInt != null) { if (endInt != null) {
if (startInt.compareTo(endInt) > 0) { if (startInt != null)
return null; {
if(startInt.compareTo(endInt) > 0) {
return null;
}
} }
return endInt.subtract(startInt).add(BigInteger.ONE);
} }
return endInt.subtract(startInt).add(BigInteger.ONE); return null;
} }
public static boolean isIp6InRange(String ip6, String ip6Range) { public static boolean isIp6InRange(String ip6, String ip6Range) {