Source:
<code>public long getEntityOwnerId() { <START> Long volumeId = getVolumeId(); <END> Long snapshotId = getSnapshotId(); Long accountId = null; if (volumeId != null) { Volume volume = _entityMgr.findById(Volume.class, volumeId); if (volume != null) { _accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.UseEntry, false, volume); } else { throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId); } } else { Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId); if (snapshot != null) { _accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.UseEntry, false, snapshot); } else { throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId); } } if(projectId != null){ final Project project = _projectService.getProject(projectId); if (project != null) { if (project.getState() == Project.State.Active) { Account projectAccount= _accountService.getAccount(project.getProjectAccountId()); _accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.UseEntry, false, projectAccount); return project.getProjectAccountId(); } else { final PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active"); ex.addProxyObject(project.getUuid(), "projectId"); throw ex; } } else { throw new InvalidParameterValueException("Unable to find project by id"); } } return CallContext.current().getCallingAccount().getId(); }</code><technical_language>accountId is unused. initialize CallContext.current().getCallingAccount() (which saves some function calls)</technical_language>

Target:
public long getEntityOwnerId() { Long volumeId = getVolumeId(); Long snapshotId = getSnapshotId(); Account callingAccount = CallContext.current().getCallingAccount(); if (volumeId != null) { Volume volume = _entityMgr.findById(Volume.class, volumeId); if (volume != null) { _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, volume); } else { throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId); } } else { Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId); if (snapshot != null) { _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, snapshot); } else { throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId); } } if(projectId != null){ final Project project = _projectService.getProject(projectId); if (project != null) { if (project.getState() == Project.State.Active) { Account projectAccount= _accountService.getAccount(project.getProjectAccountId()); _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, projectAccount); return project.getProjectAccountId(); } else { final PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active"); ex.addProxyObject(project.getUuid(), "projectId"); throw ex; } } else { throw new InvalidParameterValueException("Unable to find project by id"); } } return callingAccount.getId(); }