Program: 107308
Project: 107308
Buggy source:
@Override public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException {
  Account ctxAccount=UserContext.current().getAccount();
  Long userId=UserContext.current().getUserId();
  String name=cmd.getTemplateName();
  String displayText=cmd.getDisplayText();
  Integer bits=cmd.getBits();
  Boolean passwordEnabled=cmd.isPasswordEnabled();
  Boolean requiresHVM=cmd.getRequiresHvm();
  String url=cmd.getUrl();
  Boolean isPublic=cmd.isPublic();
  Boolean featured=cmd.isFeatured();
  Boolean isExtractable=cmd.isExtractable();
  String format=cmd.getFormat();
  Long guestOSId=cmd.getOsTypeId();
  Long zoneId=cmd.getZoneId();
  HypervisorType hypervisorType=HypervisorType.getType(cmd.getHypervisor());
  String accountName=cmd.getAccountName();
  Long domainId=cmd.getDomainId();
  Account resourceAccount=null;
  Long accountId=null;
  if (bits == null) {
    bits=Integer.valueOf(64);
  }
  if (passwordEnabled == null) {
    passwordEnabled=false;
  }
  if (requiresHVM == null) {
    requiresHVM=true;
  }
  if (isPublic == null) {
    isPublic=Boolean.FALSE;
  }
  if (isExtractable == null) {
    isExtractable=Boolean.TRUE;
  }
  if (zoneId.longValue() == -1) {
    zoneId=null;
  }
  if ((accountName == null) ^ (domainId == null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if ((ctxAccount == null) || isAdmin(ctxAccount.getType())) {
    if (domainId != null) {
      if ((ctxAccount != null) && !_domainDao.isChildDomain(ctxAccount.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
      if (accountName != null) {
        resourceAccount=_accountDao.findActiveAccount(accountName,domainId);
        if (resourceAccount == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        accountId=resourceAccount.getId();
      }
    }
 else {
      accountId=((ctxAccount != null) ? ctxAccount.getId() : null);
    }
  }
 else {
    accountId=ctxAccount.getId();
  }
  if (null == accountId && null == accountName && null == domainId && null == ctxAccount) {
    accountId=1L;
  }
  if (null == accountId) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  boolean isAdmin=_accountDao.findById(accountId).getType() == Account.ACCOUNT_TYPE_ADMIN;
  if (!isAdmin && zoneId == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (url.toLowerCase().contains("String_Node_Str")) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if ((!url.toLowerCase().endsWith("String_Node_Str")) && (!url.toLowerCase().endsWith("String_Node_Str")) && (!url.toLowerCase().endsWith("String_Node_Str"))&& (!url.toLowerCase().endsWith("String_Node_Str") && (!url.toLowerCase().endsWith("String_Node_Str")) && (!url.toLowerCase().endsWith("String_Node_Str"))&& (!url.toLowerCase().endsWith("String_Node_Str"))&& (!url.toLowerCase().endsWith("String_Node_Str")))) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + format.toLowerCase());
  }
  boolean allowPublicUserTemplates=Boolean.parseBoolean(_configDao.getValue("String_Node_Str"));
  if (!isAdmin && !allowPublicUserTemplates && isPublic) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (!isAdmin || featured == null) {
    featured=Boolean.FALSE;
  }
  if (userId == null) {
    userId=Long.valueOf(1);
  }
  return createTemplateOrIso(userId,accountId,zoneId,name,displayText,isPublic,featured,isExtractable,format,"String_Node_Str",url,null,requiresHVM,bits,passwordEnabled,guestOSId,true,hypervisorType);
}

Fixed version (ground truth):
@Override public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException {
  Account ctxAccount=UserContext.current().getAccount();
  Long userId=UserContext.current().getUserId();
  String name=cmd.getTemplateName();
  String displayText=cmd.getDisplayText();
  Integer bits=cmd.getBits();
  Boolean passwordEnabled=cmd.isPasswordEnabled();
  Boolean requiresHVM=cmd.getRequiresHvm();
  String url=cmd.getUrl();
  Boolean isPublic=cmd.isPublic();
  Boolean featured=cmd.isFeatured();
  Boolean isExtractable=cmd.isExtractable();
  String format=cmd.getFormat();
  Long guestOSId=cmd.getOsTypeId();
  Long zoneId=cmd.getZoneId();
  HypervisorType hypervisorType=HypervisorType.getType(cmd.getHypervisor());
  String accountName=cmd.getAccountName();
  Long domainId=cmd.getDomainId();
  Account resourceAccount=null;
  Long accountId=null;
  if (bits == null) {
    bits=Integer.valueOf(64);
  }
  if (passwordEnabled == null) {
    passwordEnabled=false;
  }
  if (requiresHVM == null) {
    requiresHVM=true;
  }
  if (isPublic == null) {
    isPublic=Boolean.FALSE;
  }
  if (isExtractable == null) {
    isExtractable=Boolean.TRUE;
  }
  if (zoneId.longValue() == -1) {
    zoneId=null;
  }
  if ((accountName == null) ^ (domainId == null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if ((ctxAccount == null) || isAdmin(ctxAccount.getType())) {
    if (domainId != null) {
      if ((ctxAccount != null) && !_domainDao.isChildDomain(ctxAccount.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
      if (accountName != null) {
        resourceAccount=_accountDao.findActiveAccount(accountName,domainId);
        if (resourceAccount == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        accountId=resourceAccount.getId();
      }
    }
 else {
      accountId=((ctxAccount != null) ? ctxAccount.getId() : null);
    }
  }
 else {
    accountId=ctxAccount.getId();
  }
  if (null == accountId && null == accountName && null == domainId && null == ctxAccount) {
    accountId=1L;
  }
  if (null == accountId) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  boolean isAdmin=_accountDao.findById(accountId).getType() == Account.ACCOUNT_TYPE_ADMIN;
  if (!isAdmin && zoneId == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (url.toLowerCase().contains("String_Node_Str")) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if ((!url.toLowerCase().endsWith("String_Node_Str")) && (!url.toLowerCase().endsWith("String_Node_Str")) && (!url.toLowerCase().endsWith("String_Node_Str"))&& (!url.toLowerCase().endsWith("String_Node_Str") && (!url.toLowerCase().endsWith("String_Node_Str")) && (!url.toLowerCase().endsWith("String_Node_Str"))&& (!url.toLowerCase().endsWith("String_Node_Str"))&& (!url.toLowerCase().endsWith("String_Node_Str")))) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + format.toLowerCase());
  }
  boolean allowPublicUserTemplates=Boolean.parseBoolean(_configDao.getValue("String_Node_Str"));
  if (!isAdmin && !allowPublicUserTemplates && isPublic) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (!isAdmin || featured == null) {
    featured=Boolean.FALSE;
  }
  if (userId == null) {
    userId=Long.valueOf(1);
  }
  return createTemplateOrIso(userId,accountId,zoneId,name,displayText,isPublic,featured,isExtractable,format,TemplateType.USER,url,null,requiresHVM,bits,passwordEnabled,guestOSId,true,hypervisorType);
}