Program: 166406
Project: 166406
Buggy source:
private List<RangerPolicyItem> getPolicyItemListForRes(XXResource xRes,String serviceDefName){
  List<RangerPolicyItem> policyItems=new ArrayList<RangerPolicyItem>();
  SearchCriteria sc=new SearchCriteria();
  sc.addParam("String_Node_Str",xRes.getId());
  List<VXPermMap> permMapList=xPermMapService.searchXPermMaps(sc).getVXPermMaps();
  List<VXPermObj> permObjList=xPolService.mapPermMapToPermObj(permMapList);
  XXServiceDef svcDef=daoMgr.getXXServiceDef().findByName(serviceDefName);
  if (svcDef == null) {
    return new ArrayList<RangerPolicyItem>();
  }
  XXPolicyConditionDef policyCond=daoMgr.getXXPolicyConditionDef().findByServiceDefIdAndName(svcDef.getId(),"String_Node_Str");
  for (  VXPermObj permObj : permObjList) {
    List<String> permList=permObj.getPermList();
    if (permList == null) {
      continue;
    }
    RangerPolicyItem policyItem=new RangerPolicyItem();
    List<RangerPolicyItemAccess> accesses=new ArrayList<RangerPolicyItemAccess>();
    List<RangerPolicyItemCondition> conditions=new ArrayList<RangerPolicyItemCondition>();
    if (permObj.getPermList().contains("String_Node_Str")) {
      policyItem.setDelegateAdmin(true);
    }
    for (    String perm : permList) {
      RangerPolicyItemAccess access=new RangerPolicyItemAccess();
      access.setIsAllowed(true);
      access.setType(perm);
      accesses.add(access);
    }
    if (!stringUtil.isEmpty(permObj.getIpAddress()) && policyCond != null) {
      RangerPolicyItemCondition condition=new RangerPolicyItemCondition();
      condition.setType("String_Node_Str");
      List<String> ipRangeList=Arrays.asList(permObj.getIpAddress());
      condition.setValues(ipRangeList);
      conditions.add(condition);
    }
    policyItem.setUsers(permObj.getUserList());
    policyItem.setGroups(permObj.getGroupList());
    policyItem.setAccesses(accesses);
    policyItem.setConditions(conditions);
    policyItems.add(policyItem);
  }
  return policyItems;
}

Fixed version (ground truth):
private List<RangerPolicyItem> getPolicyItemListForRes(XXResource xRes,XXServiceDef svcDef){
  List<RangerPolicyItem> policyItems=new ArrayList<RangerPolicyItem>();
  SearchCriteria sc=new SearchCriteria();
  sc.addParam("String_Node_Str",xRes.getId());
  List<VXPermMap> permMapList=xPermMapService.searchXPermMaps(sc).getVXPermMaps();
  HashMap<String,List<VXPermMap>> sortedPermMap=new HashMap<String,List<VXPermMap>>();
  if (permMapList != null) {
    for (    VXPermMap permMap : permMapList) {
      String permGrp=permMap.getPermGroup();
      List<VXPermMap> sortedList=sortedPermMap.get(permGrp);
      if (sortedList == null) {
        sortedList=new ArrayList<VXPermMap>();
        sortedPermMap.put(permGrp,sortedList);
      }
      sortedList.add(permMap);
    }
  }
  for (  Entry<String,List<VXPermMap>> entry : sortedPermMap.entrySet()) {
    List<String> userList=new ArrayList<String>();
    List<String> groupList=new ArrayList<String>();
    List<RangerPolicyItemAccess> accessList=new ArrayList<RangerPolicyItemAccess>();
    String ipAddress=null;
    RangerPolicy.RangerPolicyItem policyItem=new RangerPolicy.RangerPolicyItem();
    for (    VXPermMap permMap : entry.getValue()) {
      if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) {
        String userName=getUserName(permMap);
        if (!userList.contains(userName)) {
          userList.add(userName);
        }
      }
 else       if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) {
        String groupName=getGroupName(permMap);
        if (!groupList.contains(groupName)) {
          groupList.add(groupName);
        }
      }
      String accessType=ServiceUtil.toAccessType(permMap.getPermType());
      if (StringUtils.equalsIgnoreCase(accessType,"String_Node_Str")) {
        policyItem.setDelegateAdmin(Boolean.TRUE);
        if (svcDef.getId() == EmbeddedServiceDefsUtil.instance().getHBaseServiceDefId()) {
          accessList.add(new RangerPolicyItemAccess(accessType));
        }
      }
 else {
        accessList.add(new RangerPolicyItemAccess(accessType));
      }
      ipAddress=permMap.getIpAddress();
    }
    policyItem.setUsers(userList);
    policyItem.setGroups(groupList);
    policyItem.setAccesses(accessList);
    if (ipAddress != null && !ipAddress.isEmpty()) {
      XXPolicyConditionDef policyCond=daoMgr.getXXPolicyConditionDef().findByServiceDefIdAndName(svcDef.getId(),"String_Node_Str");
      if (policyCond != null) {
        RangerPolicy.RangerPolicyItemCondition ipCondition=new RangerPolicy.RangerPolicyItemCondition("String_Node_Str",Collections.singletonList(ipAddress));
        policyItem.getConditions().add(ipCondition);
      }
    }
    policyItems.add(policyItem);
  }
  return policyItems;
}