Fixed few coverity reported issues:Aug22 2014

This commit is contained in:
Santhosh Edukulla 2014-08-21 17:09:09 +05:30
parent 6c0a4f766e
commit 19ffc93e2e
14 changed files with 66 additions and 51 deletions

View File

@ -50,7 +50,6 @@ public class VirtualMachineTO {
String platformEmulator; String platformEmulator;
String bootArgs; String bootArgs;
String[] bootupScripts; String[] bootupScripts;
boolean rebootOnCrash;
boolean enableHA; boolean enableHA;
boolean limitCpuUse; boolean limitCpuUse;
boolean enableDynamicallyScaleVm; boolean enableDynamicallyScaleVm;

View File

@ -127,8 +127,10 @@ public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd {
VirtualRouterProvider result = _service.get(0).configure(this); VirtualRouterProvider result = _service.get(0).configure(this);
if (result != null) { if (result != null) {
VirtualRouterProviderResponse routerResponse = _responseGenerator.createVirtualRouterProviderResponse(result); VirtualRouterProviderResponse routerResponse = _responseGenerator.createVirtualRouterProviderResponse(result);
routerResponse.setResponseName(getCommandName()); if(routerResponse != null) {
this.setResponseObject(routerResponse); routerResponse.setResponseName(getCommandName());
this.setResponseObject(routerResponse);
}
} else { } else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure the virtual router provider"); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure the virtual router provider");
} }

View File

@ -110,8 +110,10 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
VirtualRouterProvider result = _service.get(0).getCreatedElement(getEntityId()); VirtualRouterProvider result = _service.get(0).getCreatedElement(getEntityId());
if (result != null) { if (result != null) {
VirtualRouterProviderResponse response = _responseGenerator.createVirtualRouterProviderResponse(result); VirtualRouterProviderResponse response = _responseGenerator.createVirtualRouterProviderResponse(result);
response.setResponseName(getCommandName()); if(response != null) {
this.setResponseObject(response); response.setResponseName(getCommandName());
this.setResponseObject(response);
}
} else { } else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network"); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
} }

View File

@ -80,13 +80,14 @@ public class ListTrafficTypesCmd extends BaseListCmd {
Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(getPhysicalNetworkId()); Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(getPhysicalNetworkId());
ListResponse<TrafficTypeResponse> response = new ListResponse<TrafficTypeResponse>(); ListResponse<TrafficTypeResponse> response = new ListResponse<TrafficTypeResponse>();
List<TrafficTypeResponse> trafficTypesResponses = new ArrayList<TrafficTypeResponse>(); List<TrafficTypeResponse> trafficTypesResponses = new ArrayList<TrafficTypeResponse>();
for (PhysicalNetworkTrafficType trafficType : trafficTypes.first()) { if(trafficTypes != null) {
TrafficTypeResponse trafficTypeResponse = _responseGenerator.createTrafficTypeResponse(trafficType); for (PhysicalNetworkTrafficType trafficType : trafficTypes.first()) {
trafficTypesResponses.add(trafficTypeResponse); TrafficTypeResponse trafficTypeResponse = _responseGenerator.createTrafficTypeResponse(trafficType);
trafficTypesResponses.add(trafficTypeResponse);
}
response.setResponses(trafficTypesResponses, trafficTypes.second());
response.setResponseName(getCommandName());
} }
response.setResponses(trafficTypesResponses, trafficTypes.second());
response.setResponseName(getCommandName());
this.setResponseObject(response); this.setResponseObject(response);
} }
} }

View File

@ -75,8 +75,10 @@ public class RegisterCmd extends BaseCmd {
public void execute() { public void execute() {
String[] keys = _accountService.createApiKeyAndSecretKey(this); String[] keys = _accountService.createApiKeyAndSecretKey(this);
RegisterResponse response = new RegisterResponse(); RegisterResponse response = new RegisterResponse();
response.setApiKey(keys[0]); if (keys != null) {
response.setSecretKey(keys[1]); response.setApiKey(keys[0]);
response.setSecretKey(keys[1]);
}
response.setObjectName("userkeys"); response.setObjectName("userkeys");
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());
this.setResponseObject(response); this.setResponseObject(response);

View File

@ -129,7 +129,7 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
} }
public Boolean isForVirtualNetwork() { public Boolean isForVirtualNetwork() {
return forVirtualNetwork == null ? true : forVirtualNetwork; return forVirtualNetwork == null ? Boolean.TRUE : forVirtualNetwork;
} }
public String getGateway() { public String getGateway() {

View File

@ -172,10 +172,6 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
} }
Long zoneId = getZoneId(); Long zoneId = getZoneId();
if (zoneId == null) {
return null;
}
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) { if (zone.getNetworkType() == NetworkType.Advanced) {
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId())); List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));

View File

@ -127,8 +127,10 @@ public class UpdateIPAddrCmd extends BaseAsyncCustomIdCmd {
NetworkRuleConflictException { NetworkRuleConflictException {
IpAddress result = _networkService.updateIP(getId(), getCustomId(), getDisplayIp()); IpAddress result = _networkService.updateIP(getId(), getCustomId(), getDisplayIp());
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, result); if(result != null) {
ipResponse.setResponseName(getCommandName()); IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, result);
setResponseObject(ipResponse); ipResponse.setResponseName(getCommandName());
setResponseObject(ipResponse);
}
} }
} }

View File

@ -749,14 +749,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
} }
Pair<NicProfile, Integer> vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm); Pair<NicProfile, Integer> vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm);
NicProfile vmNic = null;
NicProfile vmNic = vmNicPair.first(); if(vmNicPair != null) {
if (vmNic == null) { vmNic = vmNicPair.first();
continue; if (vmNic == null) {
continue;
}
deviceId = vmNicPair.second();
} }
deviceId = vmNicPair.second();
int devId = vmNic.getDeviceId(); int devId = vmNic.getDeviceId();
if (devId > deviceIds.length) { if (devId > deviceIds.length) {
throw new IllegalArgumentException("Device id for nic is too large: " + vmNic); throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);

View File

@ -3174,7 +3174,9 @@ public class NetscalerResource implements ServerResource {
scaleUpAction.set_vserver(nsVirtualServerName); // Actions Vserver, the one that is autoscaled, with CS scaleUpAction.set_vserver(nsVirtualServerName); // Actions Vserver, the one that is autoscaled, with CS
// now both are same. Not exposed in API. // now both are same. Not exposed in API.
scaleUpAction.set_profilename(profileName); scaleUpAction.set_profilename(profileName);
scaleUpAction.set_quiettime(scaleUpQuietTime); if(scaleUpQuietTime != null) {
scaleUpAction.set_quiettime(scaleUpQuietTime);
}
String scaleUpParameters = String scaleUpParameters =
"command=deployVirtualMachine" + "&" + ApiConstants.ZONE_ID + "=" + profileTO.getZoneId() + "&" + ApiConstants.SERVICE_OFFERING_ID + "=" + "command=deployVirtualMachine" + "&" + ApiConstants.ZONE_ID + "=" + profileTO.getZoneId() + "&" + ApiConstants.SERVICE_OFFERING_ID + "=" +
profileTO.getServiceOfferingId() + "&" + ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId() + "&" + ApiConstants.DISPLAY_NAME + "=" + profileTO.getServiceOfferingId() + "&" + ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId() + "&" + ApiConstants.DISPLAY_NAME + "=" +

View File

@ -341,11 +341,14 @@ public class ParamProcessWorker implements DispatchWorker {
field.set(cmdObj, Short.valueOf(paramObj.toString())); field.set(cmdObj, Short.valueOf(paramObj.toString()));
break; break;
case STRING: case STRING:
if ((paramObj != null) && paramObj.toString().length() > annotation.length()) { if ((paramObj != null)) {
s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName()); if (paramObj.toString().length() > annotation.length()) {
throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName()); s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
} else {
field.set(cmdObj, paramObj.toString());
}
} }
field.set(cmdObj, paramObj.toString());
break; break;
case TZDATE: case TZDATE:
field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString())); field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));

View File

@ -1600,7 +1600,9 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) { if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
systemIp = _ipAddrMgr.assignSystemIp(networkId, lbOwner, true, false); systemIp = _ipAddrMgr.assignSystemIp(networkId, lbOwner, true, false);
ipVO = _ipAddressDao.findById(systemIp.getId()); if (systemIp != null) {
ipVO = _ipAddressDao.findById(systemIp.getId());
}
} }
// Validate ip address // Validate ip address

View File

@ -2141,7 +2141,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
} }
if (sendCommand) { if (sendCommand) {
if (host.getHypervisorType() == HypervisorType.KVM && if (host != null && host.getHypervisorType() == HypervisorType.KVM &&
volumeToAttachStoragePool.isManaged() && volumeToAttachStoragePool.isManaged() &&
volumeToAttach.getPath() == null) { volumeToAttach.getPath() == null) {
volumeToAttach.setPath(volumeToAttach.get_iScsiName()); volumeToAttach.setPath(volumeToAttach.get_iScsiName());
@ -2178,8 +2178,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
try { try {
answer = (AttachAnswer)_agentMgr.send(hostId, cmd); answer = (AttachAnswer)_agentMgr.send(hostId, cmd);
} catch (Exception e) { } catch (Exception e) {
volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore); if(host!=null) {
volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
}
throw new CloudRuntimeException(errorMsg + " due to: " + e.getMessage()); throw new CloudRuntimeException(errorMsg + " due to: " + e.getMessage());
} }
} }
@ -2216,9 +2217,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
errorMsg += "; " + details; errorMsg += "; " + details;
} }
} }
if(host!= null) {
volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore); volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
}
throw new CloudRuntimeException(errorMsg); throw new CloudRuntimeException(errorMsg);
} }
} }

View File

@ -182,21 +182,23 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
@Override @Override
public void downloadTemplateToStorage(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) { public void downloadTemplateToStorage(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) {
long templateId = template.getId(); if(template != null) {
DataStore store = template.getDataStore(); long templateId = template.getId();
if (isTemplateUpdateable(templateId, store.getId())) { DataStore store = template.getDataStore();
if (template != null && template.getUri() != null) { if (isTemplateUpdateable(templateId, store.getId())) {
initiateTemplateDownload(template, callback); if (template.getUri() != null) {
initiateTemplateDownload(template, callback);
} else {
s_logger.info("Template url is null, cannot download");
DownloadAnswer ans = new DownloadAnswer("Template url is null", Status.UNKNOWN);
callback.complete(ans);
}
} else { } else {
s_logger.info("Template url is null, cannot download"); s_logger.info("Template download is already in progress or already downloaded");
DownloadAnswer ans = new DownloadAnswer("Template url is null", Status.UNKNOWN); DownloadAnswer ans =
new DownloadAnswer("Template download is already in progress or already downloaded", Status.UNKNOWN);
callback.complete(ans); callback.complete(ans);
} }
} else {
s_logger.info("Template download is already in progress or already downloaded");
DownloadAnswer ans =
new DownloadAnswer("Template download is already in progress or already downloaded", Status.UNKNOWN);
callback.complete(ans);
} }
} }