Program: 30450
Project: 30450
Buggy source:
/** 
 * Supports mode=find-bind. See class documentation.
 */
public String[] findAndBind(String _username,char[] _password) throws LoginException {
  StringBuffer sb=new StringBuffer(getProperty(PARAM_SEARCH_FILTER));
  substitute(sb,SUBST_SUBJECT_NAME,_username);
  String userid=sb.toString();
  DirContext ctx=null;
  String srcFilter=null;
  String[] grpList=null;
  try {
    ctx=new InitialDirContext(getLdapBindProps());
    String realUserDN=userSearch(ctx,getProperty(PARAM_USERDN),userid);
    if (realUserDN == null) {
      String msg=sm.getString("String_Node_Str",_username);
      throw new LoginException(msg);
    }
    boolean bindSuccessful=bindAsUser(realUserDN,_password);
    if (bindSuccessful == false) {
      String msg=sm.getString("String_Node_Str",realUserDN);
      throw new LoginException(msg);
    }
    sb=new StringBuffer(getProperty(PARAM_GRP_SEARCH_FILTER));
    substitute(sb,SUBST_SUBJECT_NAME,_username);
    substitute(sb,SUBST_SUBJECT_DN,realUserDN);
    srcFilter=sb.toString();
    ArrayList groupsList=new ArrayList();
    groupsList.addAll(groupSearch(ctx,getProperty(PARAM_GRPDN),srcFilter,getProperty(PARAM_GRP_TARGET)));
    groupsList.addAll(dynamicGroupSearch(ctx,getProperty(PARAM_GRPDN),getProperty(PARAM_GRP_TARGET),realUserDN));
    grpList=new String[groupsList.size()];
    groupsList.toArray(grpList);
  }
 catch (  Exception e) {
    LoginException le=new LoginException(e.toString());
    le.initCause(e);
    _logger.log(Level.SEVERE,"String_Node_Str",le);
    throw le;
  }
 finally {
    if (ctx != null) {
      try {
        ctx.close();
      }
 catch (      NamingException e) {
      }
    }
  }
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str" + srcFilter);
    StringBuffer gb=new StringBuffer();
    gb.append("String_Node_Str");
    if (grpList != null) {
      for (int i=0; i < grpList.length; i++) {
        gb.append("String_Node_Str" + grpList[i]);
      }
    }
 else {
      gb.append("String_Node_Str");
    }
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"String_Node_Str" + gb.toString());
    }
  }
  grpList=addAssignGroups(grpList);
  grpList=this.addMappedGroupNames(grpList);
  setGroupNames(_username,grpList);
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str" + _username);
  }
  return grpList;
}

Fixed version (ground truth):
/** 
 * Supports mode=find-bind. See class documentation.
 */
public String[] findAndBind(String _username,char[] _password) throws LoginException {
  StringBuffer sb=new StringBuffer(getProperty(PARAM_SEARCH_FILTER));
  substitute(sb,SUBST_SUBJECT_NAME,_username);
  String userid=sb.toString();
  DirContext ctx=null;
  String srcFilter=null;
  String[] grpList=null;
  try {
    ctx=new InitialDirContext(getLdapBindProps());
    String realUserDN=userSearch(ctx,getProperty(PARAM_USERDN),userid);
    if (realUserDN == null) {
      String msg=sm.getString("String_Node_Str",_username);
      throw new LoginException(msg);
    }
    boolean bindSuccessful=bindAsUser(realUserDN,_password);
    if (bindSuccessful == false) {
      String msg=sm.getString("String_Node_Str",realUserDN);
      throw new LoginException(msg);
    }
    sb=new StringBuffer(getProperty(PARAM_GRP_SEARCH_FILTER));
    substitute(sb,SUBST_SUBJECT_NAME,_username);
    substitute(sb,SUBST_SUBJECT_DN,realUserDN);
    srcFilter=sb.toString();
    ArrayList groupsList=new ArrayList();
    groupsList.addAll(groupSearch(ctx,getProperty(PARAM_GRPDN),srcFilter,getProperty(PARAM_GRP_TARGET)));
    groupsList.addAll(dynamicGroupSearch(ctx,getProperty(PARAM_GRPDN),getProperty(PARAM_GRP_TARGET),realUserDN));
    grpList=new String[groupsList.size()];
    groupsList.toArray(grpList);
  }
 catch (  Exception e) {
    LoginException le=new LoginException(e.toString());
    le.initCause(e);
    _logger.log(Level.SEVERE,"String_Node_Str",le);
    throw le;
  }
 finally {
    if (ctx != null) {
      try {
        ctx.close();
      }
 catch (      NamingException e) {
      }
    }
  }
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str" + srcFilter);
    StringBuffer gb=new StringBuffer();
    gb.append("String_Node_Str");
    if (grpList.length > 0) {
      for (int i=0; i < grpList.length; i++) {
        gb.append("String_Node_Str" + grpList[i]);
      }
    }
 else {
      gb.append("String_Node_Str");
    }
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"String_Node_Str" + gb.toString());
    }
  }
  grpList=addAssignGroups(grpList);
  grpList=this.addMappedGroupNames(grpList);
  setGroupNames(_username,grpList);
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str" + _username);
  }
  return grpList;
}