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

View File

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

View File

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

View File

@ -497,17 +497,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} catch (UnknownHostException e) {
throw new CloudRuntimeException("Unable to resolve " + ip);
}
try {
ch = SocketChannel.open(new InetSocketAddress(addr, Port.value()));
ch.configureBlocking(true); // make sure we are working at blocking mode
ch.socket().setKeepAlive(true);
ch.socket().setSoTimeout(60 * 1000);
try (SocketChannel ch1 = SocketChannel.open(new InetSocketAddress(addr, Port.value()));){
ch1.configureBlocking(true); // make sure we are working at blocking mode
ch1.socket().setKeepAlive(true);
ch1.socket().setSoTimeout(60 * 1000);
try {
SSLContext sslContext = Link.initSSLContext(true);
sslEngine = sslContext.createSSLEngine(ip, Port.value());
sslEngine.setUseClientMode(true);
Link.doHandshake(ch, sslEngine, true);
Link.doHandshake(ch1, sslEngine, true);
s_logger.info("SSL: Handshake done");
} catch (Exception 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();
if (managed) {
if(dsMo != null) {
String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk");
newTemplate.setPath(path);
}
}
else {
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);
}
FileReader fr = new FileReader(xmlFilePath);
BufferedReader br = new BufferedReader(fr);
try(FileReader fr = new FileReader(xmlFilePath);
BufferedReader br = new BufferedReader(fr);) {
String xml = "";
String line;
while ((line = br.readLine()) != null) {
xml += line.trim();
}
return xml;
}catch (Exception e) {
s_logger.debug(e);
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();
final Map parameterMap = new HashMap<String, String[]>();
String responseType = HttpUtils.RESPONSE_TYPE_XML;
if(paramList != null) {
for (final NameValuePair param : paramList) {
if (param.getName().equalsIgnoreCase("response")) {
responseType = param.getValue();
@ -408,6 +409,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
}
parameterMap.put(param.getName(), new String[]{param.getValue()});
}
}
// Get the type of http method being used.
parameterMap.put("httpmethod", new String[] {request.getRequestLine().getMethod()});

View File

@ -265,6 +265,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
"] is down." +
((sb != null) ? sb.toString() : ""));
if (vms != null) {
for (VMInstanceVO vm : vms) {
if (s_logger.isDebugEnabled()) {
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);
}
}
}
@Override
public void scheduleStop(VMInstanceVO vm, long hostId, WorkType type) {

View File

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

View File

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