Program: 166207
Project: 166207
Buggy source:
private void goUpGroupHierarchyLdap(Set<String> groupDNs,int groupHierarchyLevels) throws Throwable {
  if (groupHierarchyLevels <= 0 || groupDNs.isEmpty()) {
    return;
  }
  Set<String> nextLevelGroups=new HashSet<String>();
  NamingEnumeration<SearchResult> groupSearchResultEnum=null;
  try {
    createLdapContext();
    int total;
    if (pagedResultsEnabled) {
      ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pagedResultsSize,Control.NONCRITICAL)});
    }
    String groupFilter="String_Node_Str" + groupObjectClass + "String_Node_Str";
    if (groupSearchFilter != null && !groupSearchFilter.trim().isEmpty()) {
      String customFilter=groupSearchFilter.trim();
      if (!customFilter.startsWith("String_Node_Str")) {
        customFilter="String_Node_Str" + customFilter + "String_Node_Str";
      }
      groupFilter+=customFilter + "String_Node_Str";
    }
    StringBuilder filter=new StringBuilder();
    for (    String groupDN : groupDNs) {
      filter.append("String_Node_Str").append(groupMemberAttributeName).append("String_Node_Str").append(groupDN).append("String_Node_Str");
    }
    filter.append("String_Node_Str");
    groupFilter+=filter;
    LOG.info("String_Node_Str" + groupFilter);
    for (int ou=0; ou < groupSearchBase.length; ou++) {
      byte[] cookie=null;
      int counter=0;
      try {
        do {
          groupSearchResultEnum=ldapContext.search(groupSearchBase[ou],groupFilter,groupSearchControls);
          while (groupSearchResultEnum.hasMore()) {
            final SearchResult groupEntry=groupSearchResultEnum.next();
            if (groupEntry == null) {
              if (LOG.isInfoEnabled()) {
                LOG.info("String_Node_Str");
              }
              continue;
            }
            counter++;
            Attribute groupNameAttr=groupEntry.getAttributes().get(groupNameAttribute);
            if (groupNameAttr == null) {
              if (LOG.isInfoEnabled()) {
                LOG.info(groupNameAttribute + "String_Node_Str" + groupEntry.getNameInNamespace()+ "String_Node_Str");
              }
              continue;
            }
            nextLevelGroups.add(groupEntry.getNameInNamespace());
            String gName=(String)groupNameAttr.get();
            Attribute groupMemberAttr=groupEntry.getAttributes().get(groupMemberAttributeName);
            int userCount=0;
            if (groupMemberAttr == null || groupMemberAttr.size() <= 0) {
              LOG.info("String_Node_Str" + gName);
              continue;
            }
            NamingEnumeration<?> userEnum=groupMemberAttr.getAll();
            while (userEnum.hasMore()) {
              String originalUserFullName=(String)userEnum.next();
              if (originalUserFullName == null || originalUserFullName.trim().isEmpty()) {
                continue;
              }
              userCount++;
              originalUserFullName=originalUserFullName.toLowerCase();
              if (userNameMap.get(originalUserFullName) != null) {
                groupUserTable.put(gName,originalUserFullName,userNameMap.get(originalUserFullName));
              }
 else {
                groupUserTable.put(gName,originalUserFullName,originalUserFullName);
              }
              groupNameMap.put(groupEntry.getNameInNamespace().toLowerCase(),gName);
            }
            LOG.info("String_Node_Str" + gName + "String_Node_Str"+ userCount);
          }
          Control[] controls=ldapContext.getResponseControls();
          if (controls != null) {
            for (int i=0; i < controls.length; i++) {
              if (controls[i] instanceof PagedResultsResponseControl) {
                PagedResultsResponseControl prrc=(PagedResultsResponseControl)controls[i];
                total=prrc.getResultSize();
                if (total != 0) {
                  LOG.debug("String_Node_Str" + total);
                }
 else {
                  LOG.debug("String_Node_Str");
                }
                cookie=prrc.getCookie();
              }
            }
          }
 else {
            LOG.debug("String_Node_Str");
          }
          if (pagedResultsEnabled) {
            ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pagedResultsSize,cookie,Control.CRITICAL)});
          }
        }
 while (cookie != null);
        LOG.info("String_Node_Str" + counter);
      }
 catch (      RuntimeException re) {
        LOG.error("String_Node_Str",re);
        throw re;
      }
catch (      Exception t) {
        LOG.error("String_Node_Str",t);
        LOG.info("String_Node_Str" + counter);
      }
    }
  }
 catch (  RuntimeException re) {
    LOG.error("String_Node_Str",re);
    throw re;
  }
 finally {
    if (groupSearchResultEnum != null) {
      groupSearchResultEnum.close();
    }
    closeLdapContext();
  }
  goUpGroupHierarchyLdap(nextLevelGroups,groupHierarchyLevels - 1);
}

Fixed version (ground truth):
private void goUpGroupHierarchyLdap(Set<String> groupDNs,int groupHierarchyLevels) throws Throwable {
  if (groupHierarchyLevels <= 0 || groupDNs.isEmpty()) {
    return;
  }
  Set<String> nextLevelGroups=new HashSet<String>();
  NamingEnumeration<SearchResult> groupSearchResultEnum=null;
  try {
    createLdapContext();
    int total;
    if (pagedResultsEnabled) {
      ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pagedResultsSize,Control.NONCRITICAL)});
    }
    String groupFilter="String_Node_Str" + groupObjectClass + "String_Node_Str";
    if (groupSearchFilter != null && !groupSearchFilter.trim().isEmpty()) {
      String customFilter=groupSearchFilter.trim();
      if (!customFilter.startsWith("String_Node_Str")) {
        customFilter="String_Node_Str" + customFilter + "String_Node_Str";
      }
      groupFilter+=customFilter + "String_Node_Str";
    }
    StringBuilder filter=new StringBuilder();
    for (    String groupDN : groupDNs) {
      filter.append("String_Node_Str").append(groupMemberAttributeName).append("String_Node_Str").append(groupDN).append("String_Node_Str");
    }
    filter.append("String_Node_Str");
    groupFilter+=config.escapeSearchFilter(filter.toString());
    LOG.info("String_Node_Str" + groupFilter);
    for (int ou=0; ou < groupSearchBase.length; ou++) {
      byte[] cookie=null;
      int counter=0;
      try {
        do {
          groupSearchResultEnum=ldapContext.search(groupSearchBase[ou],groupFilter,groupSearchControls);
          while (groupSearchResultEnum.hasMore()) {
            final SearchResult groupEntry=groupSearchResultEnum.next();
            if (groupEntry == null) {
              if (LOG.isInfoEnabled()) {
                LOG.info("String_Node_Str");
              }
              continue;
            }
            counter++;
            Attribute groupNameAttr=groupEntry.getAttributes().get(groupNameAttribute);
            if (groupNameAttr == null) {
              if (LOG.isInfoEnabled()) {
                LOG.info(groupNameAttribute + "String_Node_Str" + groupEntry.getNameInNamespace()+ "String_Node_Str");
              }
              continue;
            }
            nextLevelGroups.add(groupEntry.getNameInNamespace());
            String gName=(String)groupNameAttr.get();
            Attribute groupMemberAttr=groupEntry.getAttributes().get(groupMemberAttributeName);
            int userCount=0;
            if (groupMemberAttr == null || groupMemberAttr.size() <= 0) {
              LOG.info("String_Node_Str" + gName);
              continue;
            }
            NamingEnumeration<?> userEnum=groupMemberAttr.getAll();
            while (userEnum.hasMore()) {
              String originalUserFullName=(String)userEnum.next();
              if (originalUserFullName == null || originalUserFullName.trim().isEmpty()) {
                continue;
              }
              userCount++;
              originalUserFullName=originalUserFullName.toLowerCase();
              if (userNameMap.get(originalUserFullName) != null) {
                groupUserTable.put(gName,originalUserFullName,userNameMap.get(originalUserFullName));
              }
 else {
                groupUserTable.put(gName,originalUserFullName,originalUserFullName);
              }
              groupNameMap.put(groupEntry.getNameInNamespace().toLowerCase(),gName);
            }
            LOG.info("String_Node_Str" + gName + "String_Node_Str"+ userCount);
          }
          Control[] controls=ldapContext.getResponseControls();
          if (controls != null) {
            for (int i=0; i < controls.length; i++) {
              if (controls[i] instanceof PagedResultsResponseControl) {
                PagedResultsResponseControl prrc=(PagedResultsResponseControl)controls[i];
                total=prrc.getResultSize();
                if (total != 0) {
                  LOG.debug("String_Node_Str" + total);
                }
 else {
                  LOG.debug("String_Node_Str");
                }
                cookie=prrc.getCookie();
              }
            }
          }
 else {
            LOG.debug("String_Node_Str");
          }
          if (pagedResultsEnabled) {
            ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pagedResultsSize,cookie,Control.CRITICAL)});
          }
        }
 while (cookie != null);
        LOG.info("String_Node_Str" + counter);
      }
 catch (      RuntimeException re) {
        LOG.error("String_Node_Str",re);
        throw re;
      }
catch (      Exception t) {
        LOG.error("String_Node_Str",t);
        LOG.info("String_Node_Str" + counter);
      }
    }
  }
 catch (  RuntimeException re) {
    LOG.error("String_Node_Str",re);
    throw re;
  }
 finally {
    if (groupSearchResultEnum != null) {
      groupSearchResultEnum.close();
    }
    closeLdapContext();
  }
  goUpGroupHierarchyLdap(nextLevelGroups,groupHierarchyLevels - 1);
}