mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fixed few coverity issues like invalid boxing unboxing issues, resource leaks, null dereferences
This commit is contained in:
parent
fc4dceaa99
commit
ef6ec7b276
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -115,8 +115,11 @@ 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
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -336,9 +336,10 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
TemplateObjectTO newTemplate = new TemplateObjectTO();
|
||||
|
||||
if (managed) {
|
||||
String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk");
|
||||
|
||||
newTemplate.setPath(path);
|
||||
if(dsMo != null) {
|
||||
String path = dsMo.getDatastorePath(managedStoragePoolRootVolumeName + ".vmdk");
|
||||
newTemplate.setPath(path);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newTemplate.setPath(templateUuidName);
|
||||
|
||||
@ -191,16 +191,18 @@ 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);
|
||||
|
||||
String xml = "";
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
xml += line.trim();
|
||||
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;
|
||||
}
|
||||
|
||||
return xml;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug(e);
|
||||
return null;
|
||||
|
||||
@ -401,12 +401,14 @@ 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;
|
||||
for (final NameValuePair param : paramList) {
|
||||
if (param.getName().equalsIgnoreCase("response")) {
|
||||
responseType = param.getValue();
|
||||
continue;
|
||||
if(paramList != null) {
|
||||
for (final NameValuePair param : paramList) {
|
||||
if (param.getName().equalsIgnoreCase("response")) {
|
||||
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.
|
||||
|
||||
@ -265,18 +265,20 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
|
||||
"] is down." +
|
||||
((sb != null) ? sb.toString() : ""));
|
||||
|
||||
for (VMInstanceVO vm : vms) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName());
|
||||
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());
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1632,12 +1632,14 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
try {
|
||||
clusterId = Long.valueOf(cluster);
|
||||
} catch (NumberFormatException e) {
|
||||
ClusterVO c = _clusterDao.findBy(cluster, podId);
|
||||
if (c == null) {
|
||||
c = new ClusterVO(dcId, podId, cluster);
|
||||
c = _clusterDao.persist(c);
|
||||
if (podId != null) {
|
||||
ClusterVO c = _clusterDao.findBy(cluster, podId.longValue());
|
||||
if (c == null) {
|
||||
c = new ClusterVO(dcId, podId.longValue(), cluster);
|
||||
c = _clusterDao.persist(c);
|
||||
}
|
||||
clusterId = c.getId();
|
||||
}
|
||||
clusterId = c.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1317,11 +1317,15 @@ public class NetUtils {
|
||||
BigInteger startInt = convertIPv6AddressToBigInteger(start);
|
||||
BigInteger endInt = convertIPv6AddressToBigInteger(end);
|
||||
if (endInt != null) {
|
||||
if (startInt.compareTo(endInt) > 0) {
|
||||
return null;
|
||||
if (startInt != 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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user