Program: 36390
Project: 36390
Buggy source:
/** 
 * Bind to the LDAP server for authentication. 
 * @param username
 * @param credential
 * @return true if the bind for authentication succeeded
 * @throws NamingException
 */
private boolean createLdapInitContext(String username,Object credential) throws Exception {
  bindDN=(String)options.get(BIND_DN);
  bindCredential=(String)options.get(BIND_CREDENTIAL);
  if ((bindCredential != null) && Util.isPasswordCommand(bindCredential))   bindCredential=new String(Util.loadPassword(bindCredential));
  String securityDomain=(String)options.get(SECURITY_DOMAIN_OPT);
  if (securityDomain != null) {
    ObjectName serviceName=new ObjectName(securityDomain);
    char[] tmp=DecodeAction.decode(bindCredential,serviceName);
    bindCredential=new String(tmp);
  }
  if (bindCredential != null && SecurityVaultUtil.isVaultFormat(bindCredential)) {
    bindCredential=SecurityVaultUtil.getValueAsString(bindCredential);
  }
  baseDN=(String)options.get(BASE_CTX_DN);
  baseFilter=(String)options.get(BASE_FILTER_OPT);
  roleFilter=(String)options.get(ROLE_FILTER_OPT);
  roleAttributeID=(String)options.get(ROLE_ATTRIBUTE_ID_OPT);
  if (roleAttributeID == null)   roleAttributeID="String_Node_Str";
  String roleAttributeIsDNOption=(String)options.get(ROLE_ATTRIBUTE_IS_DN_OPT);
  roleAttributeIsDN=Boolean.valueOf(roleAttributeIsDNOption).booleanValue();
  roleNameAttributeID=(String)options.get(ROLE_NAME_ATTRIBUTE_ID_OPT);
  if (roleNameAttributeID == null)   roleNameAttributeID="String_Node_Str";
  referralUserAttributeIDToCheck=(String)options.get(REFERRAL_USER_ATTRIBUTE_ID_TO_CHECK);
  String parseRoleNameFromDNOption=(String)options.get(PARSE_ROLE_NAME_FROM_DN_OPT);
  parseRoleNameFromDN=Boolean.valueOf(parseRoleNameFromDNOption).booleanValue();
  rolesCtxDN=(String)options.get(ROLES_CTX_DN_OPT);
  String strRecursion=(String)options.get(ROLE_RECURSION);
  try {
    recursion=Integer.parseInt(strRecursion);
  }
 catch (  NumberFormatException e) {
    PicketBoxLogger.LOGGER.debugFailureToParseNumberProperty(ROLE_RECURSION,0);
    recursion=0;
  }
  String timeLimit=(String)options.get(SEARCH_TIME_LIMIT_OPT);
  if (timeLimit != null) {
    try {
      searchTimeLimit=Integer.parseInt(timeLimit);
    }
 catch (    NumberFormatException e) {
      PicketBoxLogger.LOGGER.debugFailureToParseNumberProperty(SEARCH_TIME_LIMIT_OPT,this.searchTimeLimit);
    }
  }
  String scope=(String)options.get(SEARCH_SCOPE_OPT);
  if ("String_Node_Str".equalsIgnoreCase(scope))   searchScope=SearchControls.OBJECT_SCOPE;
 else   if ("String_Node_Str".equalsIgnoreCase(scope))   searchScope=SearchControls.ONELEVEL_SCOPE;
  if ("String_Node_Str".equalsIgnoreCase(scope))   searchScope=SearchControls.SUBTREE_SCOPE;
  distinguishedNameAttribute=(String)options.get(DISTINGUISHED_NAME_ATTRIBUTE_OPT);
  if (distinguishedNameAttribute == null)   distinguishedNameAttribute="String_Node_Str";
  InitialLdapContext ctx=null;
  ClassLoader currentTCCL=SecurityActions.getContextClassLoader();
  try {
    if (currentTCCL != null)     SecurityActions.setContextClassLoader(null);
    ctx=constructInitialLdapContext(bindDN,bindCredential);
    String userDN=bindDNAuthentication(ctx,username,credential,baseDN,baseFilter);
    SearchControls constraints=new SearchControls();
    constraints.setSearchScope(searchScope);
    constraints.setTimeLimit(searchTimeLimit);
    rolesSearch(ctx,constraints,username,userDN,recursion,0);
  }
 catch (  Exception e) {
    throw e;
  }
 finally {
    if (ctx != null)     ctx.close();
    if (currentTCCL != null)     SecurityActions.setContextClassLoader(currentTCCL);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Bind to the LDAP server for authentication. 
 * @param username
 * @param credential
 * @return true if the bind for authentication succeeded
 * @throws NamingException
 */
private boolean createLdapInitContext(String username,Object credential) throws Exception {
  bindDN=(String)options.get(BIND_DN);
  bindCredential=(String)options.get(BIND_CREDENTIAL);
  if ((bindCredential != null) && Util.isPasswordCommand(bindCredential))   bindCredential=new String(Util.loadPassword(bindCredential));
  String securityDomain=(String)options.get(SECURITY_DOMAIN_OPT);
  if (securityDomain != null) {
    ObjectName serviceName=new ObjectName(securityDomain);
    char[] tmp=DecodeAction.decode(bindCredential,serviceName);
    bindCredential=new String(tmp);
  }
  if (bindCredential != null && SecurityVaultUtil.isVaultFormat(bindCredential)) {
    bindCredential=SecurityVaultUtil.getValueAsString(bindCredential);
  }
  baseDN=(String)options.get(BASE_CTX_DN);
  baseFilter=(String)options.get(BASE_FILTER_OPT);
  roleFilter=(String)options.get(ROLE_FILTER_OPT);
  roleAttributeID=(String)options.get(ROLE_ATTRIBUTE_ID_OPT);
  if (roleAttributeID == null)   roleAttributeID="String_Node_Str";
  String roleAttributeIsDNOption=(String)options.get(ROLE_ATTRIBUTE_IS_DN_OPT);
  roleAttributeIsDN=Boolean.valueOf(roleAttributeIsDNOption).booleanValue();
  roleNameAttributeID=(String)options.get(ROLE_NAME_ATTRIBUTE_ID_OPT);
  if (roleNameAttributeID == null)   roleNameAttributeID="String_Node_Str";
  referralUserAttributeIDToCheck=(String)options.get(REFERRAL_USER_ATTRIBUTE_ID_TO_CHECK);
  String parseRoleNameFromDNOption=(String)options.get(PARSE_ROLE_NAME_FROM_DN_OPT);
  parseRoleNameFromDN=Boolean.valueOf(parseRoleNameFromDNOption).booleanValue();
  rolesCtxDN=(String)options.get(ROLES_CTX_DN_OPT);
  String strRecursion=(String)options.get(ROLE_RECURSION);
  try {
    recursion=Integer.parseInt(strRecursion);
  }
 catch (  NumberFormatException e) {
    PicketBoxLogger.LOGGER.debugFailureToParseNumberProperty(ROLE_RECURSION,0);
    recursion=0;
  }
  String timeLimit=(String)options.get(SEARCH_TIME_LIMIT_OPT);
  if (timeLimit != null) {
    try {
      searchTimeLimit=Integer.parseInt(timeLimit);
    }
 catch (    NumberFormatException e) {
      PicketBoxLogger.LOGGER.debugFailureToParseNumberProperty(SEARCH_TIME_LIMIT_OPT,this.searchTimeLimit);
    }
  }
  String scope=(String)options.get(SEARCH_SCOPE_OPT);
  if ("String_Node_Str".equalsIgnoreCase(scope))   searchScope=SearchControls.OBJECT_SCOPE;
 else   if ("String_Node_Str".equalsIgnoreCase(scope))   searchScope=SearchControls.ONELEVEL_SCOPE;
  if ("String_Node_Str".equalsIgnoreCase(scope))   searchScope=SearchControls.SUBTREE_SCOPE;
  distinguishedNameAttribute=(String)options.get(DISTINGUISHED_NAME_ATTRIBUTE_OPT);
  if (distinguishedNameAttribute == null)   distinguishedNameAttribute="String_Node_Str";
  InitialLdapContext ctx=null;
  ClassLoader currentTCCL=SecurityActions.getContextClassLoader();
  try {
    if (currentTCCL != null)     SecurityActions.setContextClassLoader(null);
    ctx=constructInitialLdapContext(bindDN,bindCredential);
    String userDN=bindDNAuthentication(ctx,username,credential,baseDN,baseFilter);
    SearchControls constraints=new SearchControls();
    constraints.setSearchScope(searchScope);
    constraints.setTimeLimit(searchTimeLimit);
    constraints.setReturningAttributes(new String[0]);
    rolesSearch(ctx,constraints,username,userDN,recursion,0);
  }
 catch (  Exception e) {
    throw e;
  }
 finally {
    if (ctx != null)     ctx.close();
    if (currentTCCL != null)     SecurityActions.setContextClassLoader(currentTCCL);
  }
  return true;
}