Program: 166329
Project: 166329
Buggy source:
private void findAdvGroupProperties(LdapContext ldapContext) throws Throwable {
  int noOfGroups=0;
  NamingEnumeration<SearchResult> groupSearchResultEnum=null;
  SearchControls groupSearchControls=new SearchControls();
  groupSearchControls.setSearchScope(config.getGroupSearchScope());
  Set<String> groupSearchAttributes=new HashSet<>();
  groupSearchAttributes.add(groupNameAttrName);
  groupSearchAttributes.add(groupMemberName);
  groupSearchAttributes.add("String_Node_Str");
  groupSearchControls.setReturningAttributes(groupSearchAttributes.toArray(new String[groupSearchAttributes.size()]));
  String extendedGroupSearchFilter="String_Node_Str" + groupObjClassName + "String_Node_Str";
  try {
    HashMap<String,Integer> ouOccurences=new HashMap<>();
    groupSearchResultEnum=ldapContext.search(searchBase,extendedGroupSearchFilter,groupSearchControls);
    while (groupSearchResultEnum.hasMore()) {
      if (noOfGroups >= 20) {
        break;
      }
      final SearchResult groupEntry=groupSearchResultEnum.next();
      if (groupEntry == null) {
        continue;
      }
      Attributes groupAttributes=groupEntry.getAttributes();
      if (groupAttributes == null) {
        logFile.println("String_Node_Str" + groupEntry.getNameInNamespace());
        continue;
      }
      String dnValue;
      Attribute dnAttr=groupAttributes.get("String_Node_Str");
      if (dnAttr != null) {
        dnValue=dnAttr.get().toString();
        String ouStr="String_Node_Str";
        int indexOfOU=dnValue.indexOf(ouStr);
        if (indexOfOU > 0) {
          dnValue=dnValue.substring(indexOfOU);
        }
 else {
          dnValue=dnValue.substring(dnValue.indexOf("String_Node_Str") + 1);
        }
      }
 else {
        dnValue=groupEntry.getNameInNamespace();
        dnValue=dnValue.substring(dnValue.indexOf("String_Node_Str") + 1);
      }
      Integer ouOccrs=ouOccurences.get(dnValue);
      if (ouOccrs == null) {
        ouOccrs=Integer.valueOf(0);
      }
      int val=ouOccrs.intValue();
      ouOccrs=Integer.valueOf(++val);
      ouOccurences.put(dnValue,ouOccrs);
      noOfGroups++;
    }
    if (!ouOccurences.isEmpty()) {
      Set<String> keys=ouOccurences.keySet();
      int maxOUOccr=0;
      for (      String key : keys) {
        int ouOccurVal=ouOccurences.get(key).intValue();
        logFile.println("String_Node_Str" + key + "String_Node_Str"+ ouOccurVal);
        if (ouOccurVal > maxOUOccr) {
          maxOUOccr=ouOccurVal;
          groupSearchBase=key;
        }
      }
    }
    groupSearchFilter=groupNameAttrName + "String_Node_Str";
    installProps.println("String_Node_Str" + groupSearchBase);
    installProps.println("String_Node_Str" + groupSearchFilter);
    ambariProps.println("String_Node_Str" + groupSearchBase);
    ambariProps.println("String_Node_Str" + groupSearchFilter);
  }
  finally {
    if (groupSearchResultEnum != null) {
      groupSearchResultEnum.close();
    }
  }
}

Fixed version (ground truth):
private void findAdvGroupProperties(LdapContext ldapContext) throws Throwable {
  int noOfGroups=0;
  NamingEnumeration<SearchResult> groupSearchResultEnum=null;
  SearchControls groupSearchControls=new SearchControls();
  groupSearchControls.setSearchScope(config.getGroupSearchScope());
  Set<String> groupSearchAttributes=new HashSet<>();
  groupSearchAttributes.add(groupNameAttrName);
  groupSearchAttributes.add(groupMemberName);
  groupSearchAttributes.add("String_Node_Str");
  groupSearchControls.setReturningAttributes(groupSearchAttributes.toArray(new String[groupSearchAttributes.size()]));
  String extendedGroupSearchFilter="String_Node_Str" + groupObjClassName + "String_Node_Str";
  try {
    HashMap<String,Integer> ouOccurences=new HashMap<>();
    if (groupSearchBase == null || groupSearchBase.isEmpty()) {
      groupSearchResultEnum=ldapContext.search(searchBase,extendedGroupSearchFilter,groupSearchControls);
    }
 else {
      groupSearchResultEnum=ldapContext.search(groupSearchBase,extendedGroupSearchFilter,groupSearchControls);
    }
    while (groupSearchResultEnum.hasMore()) {
      if (noOfGroups >= 20) {
        break;
      }
      final SearchResult groupEntry=groupSearchResultEnum.next();
      if (groupEntry == null) {
        continue;
      }
      Attributes groupAttributes=groupEntry.getAttributes();
      if (groupAttributes == null) {
        logFile.println("String_Node_Str" + groupEntry.getNameInNamespace());
        continue;
      }
      String dnValue;
      Attribute dnAttr=groupAttributes.get("String_Node_Str");
      if (dnAttr != null) {
        dnValue=dnAttr.get().toString();
        String ouStr="String_Node_Str";
        int indexOfOU=dnValue.indexOf(ouStr);
        if (indexOfOU > 0) {
          dnValue=dnValue.substring(indexOfOU);
        }
 else {
          dnValue=dnValue.substring(dnValue.indexOf("String_Node_Str") + 1);
        }
      }
 else {
        dnValue=groupEntry.getNameInNamespace();
        dnValue=dnValue.substring(dnValue.indexOf("String_Node_Str") + 1);
      }
      Integer ouOccrs=ouOccurences.get(dnValue);
      if (ouOccrs == null) {
        ouOccrs=Integer.valueOf(0);
      }
      int val=ouOccrs.intValue();
      ouOccrs=Integer.valueOf(++val);
      ouOccurences.put(dnValue,ouOccrs);
      noOfGroups++;
    }
    if (!ouOccurences.isEmpty()) {
      Set<String> keys=ouOccurences.keySet();
      int maxOUOccr=0;
      for (      String key : keys) {
        int ouOccurVal=ouOccurences.get(key).intValue();
        logFile.println("String_Node_Str" + key + "String_Node_Str"+ ouOccurVal);
        if (ouOccurVal > maxOUOccr) {
          maxOUOccr=ouOccurVal;
          groupSearchBase=key;
        }
      }
    }
    if (groupSearchFilter == null || groupSearchFilter.isEmpty()) {
      groupSearchFilter=groupNameAttrName + "String_Node_Str";
    }
    installProps.println("String_Node_Str" + groupSearchBase);
    installProps.println("String_Node_Str" + groupSearchFilter);
    ambariProps.println("String_Node_Str" + groupSearchBase);
    ambariProps.println("String_Node_Str" + groupSearchFilter);
  }
  finally {
    if (groupSearchResultEnum != null) {
      groupSearchResultEnum.close();
    }
  }
}