Program: 166481
Project: 166481
Buggy source:
@Override public VXResource updateXResource(VXResource vXResource){
  UserSessionBase currentUserSession=ContextUtil.getCurrentUserSession();
  if (currentUserSession == null) {
    throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.OPER_NO_PERMISSION);
  }
  Long assetId=vXResource.getAssetId();
  XXAsset xAsset=xADaoManager.getXXAsset().getById(assetId);
  if (xAsset == null) {
    throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.INVALID_INPUT_DATA);
  }
  if (xAsset.getActiveStatus() == XACommonEnums.STATUS_DISABLED) {
    if (!currentUserSession.isUserAdmin()) {
      logger.error("String_Node_Str");
      throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.OPER_NO_PERMISSION);
    }
  }
  if (xAsset.getAssetType() == AppConstants.ASSET_HIVE) {
    createResourcePathForHive(vXResource);
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_HBASE) {
    createResourcePathForHbase(vXResource);
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_KNOX) {
    createResourcePathForKnox(vXResource);
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_STORM) {
    createResourcePathForStorm(vXResource);
  }
  SearchCriteria searchCriteria=new SearchCriteria();
  searchCriteria.getParamList().put("String_Node_Str",vXResource.getAssetId());
  searchCriteria.getParamList().put("String_Node_Str",vXResource.getName());
  if (xAsset.getAssetType() == AppConstants.ASSET_HIVE) {
    if (stringUtil.isEmpty(vXResource.getUdfs())) {
      searchCriteria.addParam("String_Node_Str",vXResource.getTableType());
      searchCriteria.addParam("String_Node_Str",vXResource.getColumnType());
    }
 else {
      searchCriteria.addParam("String_Node_Str",vXResource.getUdfs());
    }
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_HDFS) {
    searchCriteria.addParam("String_Node_Str",vXResource.getIsRecursive());
  }
  VXResourceList vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
  if (vXResourceList != null && vXResourceList.getListSize() > 0) {
    for (    VXResource vXResourceTemp : vXResourceList.getList()) {
      if (vXResourceTemp.getId() != vXResource.getId()) {
        logger.error("String_Node_Str" + vXResource.getName());
        throw restErrorUtil.createRESTException("String_Node_Str" + vXResource.getName(),MessageEnums.ERROR_DUPLICATE_OBJECT);
      }
    }
  }
  VXResponse vXResponse=xaBizUtil.hasPermission(vXResource,AppConstants.XA_PERM_TYPE_ADMIN);
  if (vXResponse.getStatusCode() == VXResponse.STATUS_ERROR) {
    throw restErrorUtil.createRESTException(vXResponse);
  }
  if (vXResource.getCheckParentPermission() != XAConstants.BOOL_FALSE) {
    xResourceService.checkAccess(vXResource);
  }
  if (vXResource.getPolicyName() != null && !vXResource.getPolicyName().trim().isEmpty()) {
    searchCriteria=new SearchCriteria();
    searchCriteria.getParamList().put("String_Node_Str",vXResource.getPolicyName());
    vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
    if (vXResourceList != null && vXResourceList.getListSize() > 0) {
      for (      VXResource newVXResource : vXResourceList.getList()) {
        if (vXResource.getId() != newVXResource.getId() && vXResource.getPolicyName().trim().equalsIgnoreCase(newVXResource.getPolicyName().trim())) {
          logger.error("String_Node_Str" + vXResource.getPolicyName());
          logger.info("String_Node_Str" + vXResource.getPolicyName());
          throw restErrorUtil.createRESTException("String_Node_Str" + vXResource.getPolicyName(),MessageEnums.ERROR_DUPLICATE_OBJECT);
        }
      }
    }
  }
  int tempPoliciesCount=0;
  int totalPoliciesCount=1;
  String tempPolicyName=null;
  vXResourceList=null;
  if (vXResource.getPolicyName() == null || vXResource.getPolicyName().trim().isEmpty()) {
    searchCriteria=new SearchCriteria();
    searchCriteria.getParamList().put("String_Node_Str",vXResource.getAssetId());
    vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
    if (vXResourceList != null && vXResourceList.getListSize() > 0) {
      totalPoliciesCount=vXResourceList.getListSize();
      tempPoliciesCount++;
      for (      VXResource newVXResource : vXResourceList.getList()) {
        if (vXResource.getId() == newVXResource.getId()) {
          break;
        }
        tempPoliciesCount++;
      }
      tempPolicyName=xAsset.getName() + "String_Node_Str" + tempPoliciesCount+ "String_Node_Str"+ DateUtil.dateToString(DateUtil.getUTCDate(),"String_Node_Str");
      vXResource.setPolicyName(tempPolicyName);
      vXResourceList=null;
    }
 else {
      tempPoliciesCount++;
      tempPolicyName=xAsset.getName() + "String_Node_Str" + tempPoliciesCount+ "String_Node_Str"+ DateUtil.dateToString(DateUtil.getUTCDate(),"String_Node_Str");
      vXResource.setPolicyName(tempPolicyName);
    }
    while (true) {
      searchCriteria=new SearchCriteria();
      searchCriteria.getParamList().put("String_Node_Str",vXResource.getPolicyName());
      vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
      if (vXResourceList == null || vXResourceList.getListSize() == 0) {
        break;
      }
 else {
        tempPolicyName=xAsset.getName() + "String_Node_Str" + totalPoliciesCount+ "String_Node_Str"+ DateUtil.dateToString(DateUtil.getUTCDate(),"String_Node_Str");
        vXResource.setPolicyName(tempPolicyName);
      }
    }
  }
  XXResource xResouce=xADaoManager.getXXResource().getById(vXResource.getId());
  List<XXTrxLog> trxLogList=xResourceService.getTransactionLog(vXResource,xResouce,"String_Node_Str");
  VXResource resource=super.updateXResource(vXResource);
  List<VXPermMap> newPermMapList=vXResource.getPermMapList();
  searchCriteria=new SearchCriteria();
  searchCriteria.addParam("String_Node_Str",vXResource.getId());
  VXPermMapList prevPermMaps=xPermMapService.searchXPermMaps(searchCriteria);
  List<VXPermMap> prevPermMapList=new ArrayList<VXPermMap>();
  if (prevPermMaps != null) {
    prevPermMapList=prevPermMaps.getVXPermMaps();
  }
  List<VXPermMap> permMaps=new ArrayList<VXPermMap>();
  List<VXAuditMap> auditMaps=new ArrayList<VXAuditMap>();
  List<VXPermMap> permMapsToDelete=new ArrayList<VXPermMap>();
  List<VXAuditMap> auditMapsToDelete=new ArrayList<VXAuditMap>();
  if (newPermMapList != null) {
    for (    VXPermMap newObj : newPermMapList) {
      if (newObj.getUserId() == null && newObj.getGroupId() == null && !stringUtil.isEmpty(newObj.getUserName())) {
        XXUser xxUser=xADaoManager.getXXUser().findByUserName(newObj.getUserName());
        if (xxUser != null) {
          newObj.setUserId(xxUser.getId());
        }
 else {
          VXUser vxUser=new VXUser();
          vxUser.setName(newObj.getUserName());
          vxUser.setDescription(newObj.getUserName());
          vxUser=xUserService.createResource(vxUser);
          newObj.setUserId(vxUser.getId());
        }
      }
      newObj.setResourceId(resource.getId());
      if (newObj.getId() != null) {
        for (        VXPermMap oldObj : prevPermMapList) {
          if (oldObj.getId().equals(newObj.getId())) {
            if (oldObj.getPermType() != newObj.getPermType()) {
              logger.error("String_Node_Str",new IllegalStateException());
              break;
            }
 else {
              xPermMapService.updateResource(newObj);
              trxLogList.addAll(xPermMapService.getTransactionLog(newObj,oldObj,"String_Node_Str"));
            }
          }
        }
      }
 else {
        newObj=xPermMapService.createResource(newObj);
        trxLogList.addAll(xPermMapService.getTransactionLog(newObj,"String_Node_Str"));
      }
      permMaps.add(newObj);
    }
  }
  if (prevPermMapList != null) {
    for (    VXPermMap oldObj : prevPermMapList) {
      boolean found=false;
      if (newPermMapList != null) {
        for (        VXPermMap newObj : newPermMapList) {
          if (newObj.getId() != null && newObj.getId().equals(oldObj.getId())) {
            found=true;
            break;
          }
        }
      }
      if (!found) {
        trxLogList.addAll(xPermMapService.getTransactionLog(oldObj,"String_Node_Str"));
        permMapsToDelete.add(oldObj);
      }
    }
  }
  List<VXAuditMap> newAuditMapList=vXResource.getAuditList();
  VXAuditMapList vXAuditMaps=xAuditMapService.searchXAuditMaps(searchCriteria);
  List<VXAuditMap> prevAuditMapList=new ArrayList<VXAuditMap>();
  if (vXAuditMaps != null && vXAuditMaps.getResultSize() != 0) {
    prevAuditMapList=vXAuditMaps.getList();
  }
  if (newAuditMapList != null) {
    for (    VXAuditMap newObj : newAuditMapList) {
      if (newObj.getId() != null) {
        for (        VXAuditMap oldObj : prevAuditMapList) {
          if (oldObj.getId().equals(newObj.getId()) && oldObj.getAuditType() != newObj.getAuditType()) {
            logger.error("String_Node_Str",new IllegalStateException());
            break;
          }
        }
      }
 else {
        newObj=xAuditMapService.createResource(newObj);
        trxLogList.addAll(xAuditMapService.getTransactionLog(newObj,"String_Node_Str"));
      }
      auditMaps.add(newObj);
    }
  }
  if (prevAuditMapList != null) {
    for (    VXAuditMap oldObj : prevAuditMapList) {
      boolean found=false;
      if (newAuditMapList != null) {
        for (        VXAuditMap newObj : newAuditMapList) {
          if (newObj.getId() != null && newObj.getId().equals(oldObj.getId())) {
            found=true;
            break;
          }
        }
      }
      if (!found) {
        trxLogList.addAll(xAuditMapService.getTransactionLog(oldObj,"String_Node_Str"));
        auditMapsToDelete.add(oldObj);
      }
    }
  }
  xaBizUtil.createTrxLog(trxLogList);
  for (  VXPermMap permMap : permMapsToDelete) {
    xPermMapService.deleteResource(permMap.getId());
  }
  for (  VXAuditMap auditMap : auditMapsToDelete) {
    xAuditMapService.deleteResource(auditMap.getId());
  }
  resource.setPermMapList(permMaps);
  resource.setAuditList(auditMaps);
  return resource;
}

Fixed version (ground truth):
@Override public VXResource updateXResource(VXResource vXResource){
  UserSessionBase currentUserSession=ContextUtil.getCurrentUserSession();
  if (currentUserSession == null) {
    throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.OPER_NO_PERMISSION);
  }
  Long assetId=vXResource.getAssetId();
  XXAsset xAsset=xADaoManager.getXXAsset().getById(assetId);
  if (xAsset == null) {
    throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.INVALID_INPUT_DATA);
  }
  if (xAsset.getActiveStatus() == XACommonEnums.STATUS_DISABLED) {
    if (!currentUserSession.isUserAdmin()) {
      logger.error("String_Node_Str");
      throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.OPER_NO_PERMISSION);
    }
  }
  if (xAsset.getAssetType() == AppConstants.ASSET_HIVE) {
    createResourcePathForHive(vXResource);
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_HBASE) {
    createResourcePathForHbase(vXResource);
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_KNOX) {
    createResourcePathForKnox(vXResource);
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_STORM) {
    createResourcePathForStorm(vXResource);
  }
  SearchCriteria searchCriteria=new SearchCriteria();
  searchCriteria.getParamList().put("String_Node_Str",vXResource.getAssetId());
  searchCriteria.getParamList().put("String_Node_Str",vXResource.getName());
  if (xAsset.getAssetType() == AppConstants.ASSET_HIVE) {
    if (stringUtil.isEmpty(vXResource.getUdfs())) {
      searchCriteria.addParam("String_Node_Str",vXResource.getTableType());
      searchCriteria.addParam("String_Node_Str",vXResource.getColumnType());
    }
 else {
      searchCriteria.addParam("String_Node_Str",vXResource.getUdfs());
    }
  }
 else   if (xAsset.getAssetType() == AppConstants.ASSET_HDFS) {
    searchCriteria.addParam("String_Node_Str",vXResource.getIsRecursive());
  }
  VXResourceList vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
  if (vXResourceList != null && vXResourceList.getListSize() > 0) {
    if (vXResource != null && vXResource.getId() != null) {
      for (      VXResource vXResourceTemp : vXResourceList.getList()) {
        if (vXResourceTemp != null && !(vXResource.getId().equals(vXResourceTemp.getId()))) {
          logger.error("String_Node_Str" + vXResource.getName());
          throw restErrorUtil.createRESTException("String_Node_Str" + vXResource.getName(),MessageEnums.ERROR_DUPLICATE_OBJECT);
        }
      }
    }
  }
  VXResponse vXResponse=xaBizUtil.hasPermission(vXResource,AppConstants.XA_PERM_TYPE_ADMIN);
  if (vXResponse.getStatusCode() == VXResponse.STATUS_ERROR) {
    throw restErrorUtil.createRESTException(vXResponse);
  }
  if (vXResource.getCheckParentPermission() != XAConstants.BOOL_FALSE) {
    xResourceService.checkAccess(vXResource);
  }
  if (vXResource.getPolicyName() != null && !vXResource.getPolicyName().trim().isEmpty()) {
    searchCriteria=new SearchCriteria();
    searchCriteria.getParamList().put("String_Node_Str",vXResource.getPolicyName());
    vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
    if (vXResourceList != null && vXResourceList.getListSize() > 0) {
      if (vXResource != null && vXResource.getId() != null) {
        for (        VXResource newVXResource : vXResourceList.getList()) {
          if (newVXResource != null && newVXResource.getId() != null) {
            if (!vXResource.getId().equals(newVXResource.getId()) && vXResource.getPolicyName().trim().equalsIgnoreCase((newVXResource.getPolicyName() != null ? newVXResource.getPolicyName().trim() : newVXResource.getPolicyName()))) {
              logger.error("String_Node_Str" + vXResource.getPolicyName());
              throw restErrorUtil.createRESTException("String_Node_Str" + vXResource.getPolicyName(),MessageEnums.ERROR_DUPLICATE_OBJECT);
            }
          }
        }
      }
    }
  }
  int tempPoliciesCount=0;
  int totalPoliciesCount=1;
  String tempPolicyName=null;
  vXResourceList=null;
  if (vXResource != null && (vXResource.getPolicyName() == null || vXResource.getPolicyName().trim().isEmpty())) {
    searchCriteria=new SearchCriteria();
    searchCriteria.getParamList().put("String_Node_Str",vXResource.getAssetId());
    vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
    if (vXResourceList != null && vXResourceList.getListSize() > 0) {
      totalPoliciesCount=vXResourceList.getListSize();
      tempPoliciesCount++;
      for (      VXResource newVXResource : vXResourceList.getList()) {
        if (newVXResource != null && newVXResource.getId() != null) {
          if (vXResource.getId().equals(newVXResource.getId())) {
            break;
          }
        }
        tempPoliciesCount++;
      }
      tempPolicyName=xAsset.getName() + "String_Node_Str" + tempPoliciesCount+ "String_Node_Str"+ DateUtil.dateToString(DateUtil.getUTCDate(),"String_Node_Str");
      vXResource.setPolicyName(tempPolicyName);
      vXResourceList=null;
    }
 else {
      tempPoliciesCount++;
      tempPolicyName=xAsset.getName() + "String_Node_Str" + tempPoliciesCount+ "String_Node_Str"+ DateUtil.dateToString(DateUtil.getUTCDate(),"String_Node_Str");
      vXResource.setPolicyName(tempPolicyName);
    }
    while (true) {
      searchCriteria=new SearchCriteria();
      searchCriteria.getParamList().put("String_Node_Str",vXResource.getPolicyName());
      vXResourceList=xResourceService.searchXResourcesWithoutLogin(searchCriteria);
      if (vXResourceList == null || vXResourceList.getListSize() == 0) {
        break;
      }
 else {
        tempPolicyName=xAsset.getName() + "String_Node_Str" + totalPoliciesCount+ "String_Node_Str"+ DateUtil.dateToString(DateUtil.getUTCDate(),"String_Node_Str");
        vXResource.setPolicyName(tempPolicyName);
      }
    }
  }
  XXResource xResouce=xADaoManager.getXXResource().getById(vXResource.getId());
  List<XXTrxLog> trxLogList=xResourceService.getTransactionLog(vXResource,xResouce,"String_Node_Str");
  VXResource resource=super.updateXResource(vXResource);
  List<VXPermMap> newPermMapList=vXResource.getPermMapList();
  searchCriteria=new SearchCriteria();
  searchCriteria.addParam("String_Node_Str",vXResource.getId());
  VXPermMapList prevPermMaps=xPermMapService.searchXPermMaps(searchCriteria);
  List<VXPermMap> prevPermMapList=new ArrayList<VXPermMap>();
  if (prevPermMaps != null) {
    prevPermMapList=prevPermMaps.getVXPermMaps();
  }
  List<VXPermMap> permMaps=new ArrayList<VXPermMap>();
  List<VXAuditMap> auditMaps=new ArrayList<VXAuditMap>();
  List<VXPermMap> permMapsToDelete=new ArrayList<VXPermMap>();
  List<VXAuditMap> auditMapsToDelete=new ArrayList<VXAuditMap>();
  if (newPermMapList != null) {
    for (    VXPermMap newObj : newPermMapList) {
      if (newObj.getUserId() == null && newObj.getGroupId() == null && !stringUtil.isEmpty(newObj.getUserName())) {
        XXUser xxUser=xADaoManager.getXXUser().findByUserName(newObj.getUserName());
        if (xxUser != null) {
          newObj.setUserId(xxUser.getId());
        }
 else {
          VXUser vxUser=new VXUser();
          vxUser.setName(newObj.getUserName());
          vxUser.setDescription(newObj.getUserName());
          vxUser=xUserService.createResource(vxUser);
          newObj.setUserId(vxUser.getId());
        }
      }
      newObj.setResourceId(resource.getId());
      if (newObj.getId() != null) {
        for (        VXPermMap oldObj : prevPermMapList) {
          if (oldObj.getId().equals(newObj.getId())) {
            if (oldObj.getPermType() != newObj.getPermType()) {
              logger.error("String_Node_Str",new IllegalStateException());
              break;
            }
 else {
              xPermMapService.updateResource(newObj);
              trxLogList.addAll(xPermMapService.getTransactionLog(newObj,oldObj,"String_Node_Str"));
            }
          }
        }
      }
 else {
        newObj=xPermMapService.createResource(newObj);
        trxLogList.addAll(xPermMapService.getTransactionLog(newObj,"String_Node_Str"));
      }
      permMaps.add(newObj);
    }
  }
  if (prevPermMapList != null) {
    for (    VXPermMap oldObj : prevPermMapList) {
      boolean found=false;
      if (newPermMapList != null) {
        for (        VXPermMap newObj : newPermMapList) {
          if (newObj.getId() != null && newObj.getId().equals(oldObj.getId())) {
            found=true;
            break;
          }
        }
      }
      if (!found) {
        trxLogList.addAll(xPermMapService.getTransactionLog(oldObj,"String_Node_Str"));
        permMapsToDelete.add(oldObj);
      }
    }
  }
  List<VXAuditMap> newAuditMapList=vXResource.getAuditList();
  VXAuditMapList vXAuditMaps=xAuditMapService.searchXAuditMaps(searchCriteria);
  List<VXAuditMap> prevAuditMapList=new ArrayList<VXAuditMap>();
  if (vXAuditMaps != null && vXAuditMaps.getResultSize() != 0) {
    prevAuditMapList=vXAuditMaps.getList();
  }
  if (newAuditMapList != null) {
    for (    VXAuditMap newObj : newAuditMapList) {
      if (newObj.getId() != null) {
        for (        VXAuditMap oldObj : prevAuditMapList) {
          if (oldObj.getId().equals(newObj.getId()) && oldObj.getAuditType() != newObj.getAuditType()) {
            logger.error("String_Node_Str",new IllegalStateException());
            break;
          }
        }
      }
 else {
        newObj=xAuditMapService.createResource(newObj);
        trxLogList.addAll(xAuditMapService.getTransactionLog(newObj,"String_Node_Str"));
      }
      auditMaps.add(newObj);
    }
  }
  if (prevAuditMapList != null) {
    for (    VXAuditMap oldObj : prevAuditMapList) {
      boolean found=false;
      if (newAuditMapList != null) {
        for (        VXAuditMap newObj : newAuditMapList) {
          if (newObj.getId() != null && newObj.getId().equals(oldObj.getId())) {
            found=true;
            break;
          }
        }
      }
      if (!found) {
        trxLogList.addAll(xAuditMapService.getTransactionLog(oldObj,"String_Node_Str"));
        auditMapsToDelete.add(oldObj);
      }
    }
  }
  xaBizUtil.createTrxLog(trxLogList);
  for (  VXPermMap permMap : permMapsToDelete) {
    xPermMapService.deleteResource(permMap.getId());
  }
  for (  VXAuditMap auditMap : auditMapsToDelete) {
    xAuditMapService.deleteResource(auditMap.getId());
  }
  resource.setPermMapList(permMaps);
  resource.setAuditList(auditMaps);
  return resource;
}