CLOUDSTACK-10156: Fix Coverity new problems CID(1349987, 1349986, 1347248) (#2332)

Fix Coverity new problems CID(1349987, 1349986, 1347248).
This commit is contained in:
Rafael Weingärtner 2017-11-23 04:10:53 -02:00 committed by Rohit Yadav
parent 632479d8f8
commit cb9c7adddf
3 changed files with 11 additions and 17 deletions

View File

@ -21,7 +21,6 @@ import java.util.List;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
@ -29,10 +28,10 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
import org.apache.cloudstack.api.response.QuotaStatementResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.vo.QuotaUsageVO;
import org.apache.cloudstack.api.response.QuotaStatementItemResponse;
import org.apache.cloudstack.api.response.QuotaStatementResponse;
import org.apache.cloudstack.quota.vo.QuotaUsageVO;
import org.apache.log4j.Logger;
import com.cloud.user.Account;
@ -62,7 +61,7 @@ public class QuotaStatementCmd extends BaseCmd {
private Long accountId;
@Inject
QuotaResponseBuilder _responseBuilder;
private QuotaResponseBuilder _responseBuilder;
public Long getAccountId() {
return accountId;
@ -119,9 +118,9 @@ public class QuotaStatementCmd extends BaseCmd {
@Override
public long getEntityOwnerId() {
Long accountId = _accountService.getActiveAccountByName(accountName, domainId).getAccountId();
if (accountId == null) {
return CallContext.current().getCallingAccount().getId();
Account activeAccountByName = _accountService.getActiveAccountByName(accountName, domainId);
if (activeAccountByName != null) {
return activeAccountByName.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM;
}

View File

@ -21,10 +21,9 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xen610;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@ -39,8 +38,8 @@ import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork;
import com.cloud.network.Networks.TrafficType;
import com.cloud.resource.CommandWrapper;
import com.cloud.resource.ResourceWrapper;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.Network;
@ -66,7 +65,6 @@ public final class XenServer610MigrateWithStorageReceiveCommandWrapper extends C
// agent attache. Seriliaze the SR and Network objects here to a string and pass in
// the answer object. It'll be deserialzed and object created in migrate with
// storage send command execution.
Gson gson = new Gson();
// Get a map of all the SRs to which the vdis will be migrated.
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
@ -76,7 +74,6 @@ public final class XenServer610MigrateWithStorageReceiveCommandWrapper extends C
volumeToSr.add(new Pair<VolumeTO, Object>(entry.first(), sr));
}
// Get the list of networks to which the vifs will attach.
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<Pair<NicTO, Object>>();
for (final NicTO nicTo : vmSpec.getNics()) {

View File

@ -20,11 +20,10 @@
package com.cloud.hypervisor.xenserver.resource.wrapper.xen610;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.List;
import com.google.gson.Gson;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@ -36,8 +35,8 @@ import com.cloud.agent.api.to.VolumeTO;
import com.cloud.hypervisor.xenserver.resource.XenServer610Resource;
import com.cloud.resource.CommandWrapper;
import com.cloud.resource.ResourceWrapper;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Network;
import com.xensource.xenapi.SR;
@ -73,7 +72,6 @@ public final class XenServer610MigrateWithStorageSendCommandWrapper extends Comm
// agent attache. Seriliaze the SR and Network objects here to a string and pass in
// the answer object. It'll be deserialzed and object created in migrate with
// storage send command execution.
Gson gson = new Gson();
final Map<String, String> other = new HashMap<String, String>();
other.put("live", "true");