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,7 +115,10 @@ 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

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,10 +336,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
TemplateObjectTO newTemplate = new TemplateObjectTO(); TemplateObjectTO newTemplate = new TemplateObjectTO();
if (managed) { if (managed) {
if(dsMo != null) {
String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk"); String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk");
newTemplate.setPath(path); newTemplate.setPath(path);
} }
}
else { else {
newTemplate.setPath(templateUuidName); newTemplate.setPath(templateUuidName);
} }

View File

@ -191,20 +191,22 @@ 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; return xml;
}catch (Exception e) { }catch (Exception e) {
s_logger.debug(e); s_logger.debug(e);
return null; return null;
} }
} catch (Exception e) {
s_logger.debug(e);
return null;
}
} }
} }

View File

@ -401,6 +401,7 @@ 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;
if(paramList != null) {
for (final NameValuePair param : paramList) { for (final NameValuePair param : paramList) {
if (param.getName().equalsIgnoreCase("response")) { if (param.getName().equalsIgnoreCase("response")) {
responseType = param.getValue(); responseType = param.getValue();
@ -408,6 +409,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
} }
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.
parameterMap.put("httpmethod", new String[] {request.getRequestLine().getMethod()}); parameterMap.put("httpmethod", new String[] {request.getRequestLine().getMethod()});

View File

@ -265,6 +265,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
"] is down." + "] is down." +
((sb != null) ? sb.toString() : "")); ((sb != null) ? sb.toString() : ""));
if (vms != null) {
for (VMInstanceVO vm : vms) { for (VMInstanceVO vm : vms) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName()); s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName());
@ -279,6 +280,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
scheduleRestart(vm, investigate); scheduleRestart(vm, investigate);
} }
} }
}
@Override @Override
public void scheduleStop(VMInstanceVO vm, long hostId, WorkType type) { public void scheduleStop(VMInstanceVO vm, long hostId, WorkType type) {

View File

@ -1632,14 +1632,16 @@ 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) {
ClusterVO c = _clusterDao.findBy(cluster, podId.longValue());
if (c == null) { if (c == null) {
c = new ClusterVO(dcId, podId, cluster); c = new ClusterVO(dcId, podId.longValue(), cluster);
c = _clusterDao.persist(c); c = _clusterDao.persist(c);
} }
clusterId = c.getId(); clusterId = c.getId();
} }
} }
}
if (startup instanceof StartupRoutingCommand) { if (startup instanceof StartupRoutingCommand) {
StartupRoutingCommand ssCmd = ((StartupRoutingCommand)startup); StartupRoutingCommand ssCmd = ((StartupRoutingCommand)startup);

View File

@ -1317,12 +1317,16 @@ 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 != null)
{
if(startInt.compareTo(endInt) > 0) { if(startInt.compareTo(endInt) > 0) {
return null; 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) {
if (ip6Range == null) { if (ip6Range == null) {