Program: 166328
Project: 166328
Buggy source:
private void findAdvUserProperties(LdapContext ldapContext,boolean isOutputNeeded) throws Throwable {
  int noOfUsers;
  NamingEnumeration<SearchResult> userSearchResultEnum=null;
  SearchControls userSearchControls=new SearchControls();
  userSearchControls.setSearchScope(config.getUserSearchScope());
  if (userNameAttribute != null && !userNameAttribute.isEmpty()) {
    Set<String> userSearchAttributes=new HashSet<>();
    userSearchAttributes.add(userNameAttribute);
    userSearchAttributes.add(userGroupMemberName);
    userSearchAttributes.add("String_Node_Str");
    userSearchControls.setReturningAttributes(userSearchAttributes.toArray(new String[userSearchAttributes.size()]));
  }
 else {
    userSearchControls.setReturningAttributes(new java.lang.String[]{"String_Node_Str","String_Node_Str"});
  }
  String extendedUserSearchFilter="String_Node_Str" + userObjClassName + "String_Node_Str";
  try {
    HashMap<String,Integer> ouOccurences=new HashMap<>();
    userSearchResultEnum=ldapContext.search(searchBase,extendedUserSearchFilter,userSearchControls);
    noOfUsers=0;
    while (userSearchResultEnum.hasMore()) {
      if (noOfUsers >= 20) {
        break;
      }
      final SearchResult userEntry=userSearchResultEnum.next();
      if (userEntry == null) {
        logFile.println("String_Node_Str");
        continue;
      }
      Attributes attributes=userEntry.getAttributes();
      if (attributes == null) {
        logFile.println("String_Node_Str" + userEntry.getNameInNamespace());
        continue;
      }
      String dnValue;
      Attribute dnAttr=attributes.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=userEntry.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);
      noOfUsers++;
    }
    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;
          userSearchBase=key;
        }
      }
    }
    userSearchFilter=userNameAttribute + "String_Node_Str";
    if (isOutputNeeded) {
      installProps.println("String_Node_Str" + userSearchBase);
      installProps.println("String_Node_Str" + userSearchFilter);
      ambariProps.println("String_Node_Str" + userSearchBase);
      ambariProps.println("String_Node_Str" + userSearchFilter);
    }
  }
 catch (  NamingException ne) {
    String msg="String_Node_Str" + "String_Node_Str" + "String_Node_Str";
    if ((config.getUserNameAttribute() != null && !config.getUserNameAttribute().isEmpty()) || (config.getUserObjectClass() != null && !config.getUserObjectClass().isEmpty()) || (config.getGroupNameAttribute() != null && !config.getGroupNameAttribute().isEmpty())) {
      throw new Exception("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
    }
 else {
      throw new Exception(msg + ne);
    }
  }
 finally {
    if (userSearchResultEnum != null) {
      userSearchResultEnum.close();
    }
  }
}

Fixed version (ground truth):
private void findAdvUserProperties(LdapContext ldapContext,boolean isOutputNeeded) throws Throwable {
  int noOfUsers;
  NamingEnumeration<SearchResult> userSearchResultEnum=null;
  SearchControls userSearchControls=new SearchControls();
  userSearchControls.setSearchScope(config.getUserSearchScope());
  if (userNameAttribute != null && !userNameAttribute.isEmpty()) {
    Set<String> userSearchAttributes=new HashSet<>();
    userSearchAttributes.add(userNameAttribute);
    userSearchAttributes.add(userGroupMemberName);
    userSearchAttributes.add("String_Node_Str");
    userSearchControls.setReturningAttributes(userSearchAttributes.toArray(new String[userSearchAttributes.size()]));
  }
 else {
    userSearchControls.setReturningAttributes(new java.lang.String[]{"String_Node_Str","String_Node_Str"});
  }
  String extendedUserSearchFilter="String_Node_Str" + userObjClassName + "String_Node_Str";
  try {
    HashMap<String,Integer> ouOccurences=new HashMap<>();
    if (userSearchBase == null || userSearchBase.isEmpty()) {
      userSearchResultEnum=ldapContext.search(searchBase,extendedUserSearchFilter,userSearchControls);
    }
 else {
      userSearchResultEnum=ldapContext.search(userSearchBase,extendedUserSearchFilter,userSearchControls);
    }
    noOfUsers=0;
    while (userSearchResultEnum.hasMore()) {
      if (noOfUsers >= 20) {
        break;
      }
      final SearchResult userEntry=userSearchResultEnum.next();
      if (userEntry == null) {
        logFile.println("String_Node_Str");
        continue;
      }
      Attributes attributes=userEntry.getAttributes();
      if (attributes == null) {
        logFile.println("String_Node_Str" + userEntry.getNameInNamespace());
        continue;
      }
      String dnValue;
      Attribute dnAttr=attributes.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=userEntry.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);
      noOfUsers++;
    }
    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;
          userSearchBase=key;
        }
      }
    }
    if (userSearchFilter == null || userSearchFilter.isEmpty()) {
      userSearchFilter=userNameAttribute + "String_Node_Str";
    }
    if (isOutputNeeded) {
      installProps.println("String_Node_Str" + userSearchBase);
      installProps.println("String_Node_Str" + userSearchFilter);
      ambariProps.println("String_Node_Str" + userSearchBase);
      ambariProps.println("String_Node_Str" + userSearchFilter);
    }
  }
 catch (  NamingException ne) {
    String msg="String_Node_Str" + "String_Node_Str" + "String_Node_Str";
    if ((config.getUserNameAttribute() != null && !config.getUserNameAttribute().isEmpty()) || (config.getUserObjectClass() != null && !config.getUserObjectClass().isEmpty()) || (config.getGroupNameAttribute() != null && !config.getGroupNameAttribute().isEmpty())) {
      throw new Exception("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
    }
 else {
      throw new Exception(msg + ne);
    }
  }
 finally {
    if (userSearchResultEnum != null) {
      userSearchResultEnum.close();
    }
  }
}