Program: 29536
Project: 29536
Buggy source:
/** 
 * Obtains the real password from the domain specific keystore given an alias
 * @param host host that we are connecting to
 * @param alias password alias of form ${ALIAS=xxx}
 * @return real password of ssh user, null if not found
 */
String expandPasswordAlias(String host,String alias,boolean verifyConn){
  String expandedPassword=null;
  boolean connStatus=false;
  try {
    File domainsDirFile=DomainDirs.getDefaultDomainsDir();
    File[] files=domainsDirFile.listFiles(new FileFilter(){
      public boolean accept(      File f){
        return f.isDirectory();
      }
    }
);
    for (    File f : files) {
      System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,f.getAbsolutePath());
      try {
        final MasterPassword masterPasswordHelper=Globals.getDefaultHabitat().getService(MasterPassword.class,"String_Node_Str");
        final PasswordAdapter pa=masterPasswordHelper.getMasterPasswordAdapter();
        final boolean exists=pa.aliasExists(alias);
        if (exists) {
          String mPass=getMasterPassword(f.getName());
          masterPasswordHelper.setMasterPassword(mPass.toCharArray());
          expandedPassword=masterPasswordHelper.getMasterPasswordAdapter().getPasswordForAlias(alias);
        }
      }
 catch (      Exception e) {
        if (logger.isLoggable(Level.FINER)) {
          logger.finer(StringUtils.cat("String_Node_Str",alias,e.getMessage()));
        }
        logger.warning(Strings.get("String_Node_Str",f.getName()));
        continue;
      }
      if (expandedPassword != null) {
        SSHLauncher sshL=new SSHLauncher();
        if (host != null) {
          sshpassword=expandedPassword;
          sshL.init(getRemoteUser(),host,getRemotePort(),sshpassword,null,null,logger);
          connStatus=sshL.checkPasswordAuth();
          if (!connStatus) {
            logger.warning(Strings.get("String_Node_Str",f.getName()));
          }
        }
 else {
          sshkeypassphrase=expandedPassword;
          if (verifyConn) {
            sshL.init(getRemoteUser(),hosts[0],getRemotePort(),sshpassword,getSshKeyFile(),sshkeypassphrase,logger);
            connStatus=sshL.checkConnection();
            if (!connStatus) {
              logger.warning(Strings.get("String_Node_Str",f.getName()));
            }
          }
        }
        if (connStatus) {
          break;
        }
      }
    }
  }
 catch (  IOException ioe) {
    if (logger.isLoggable(Level.FINER)) {
      logger.finer(ioe.getMessage());
    }
  }
  return expandedPassword;
}

Fixed version (ground truth):
/** 
 * Obtains the real password from the domain specific keystore given an alias
 * @param host host that we are connecting to
 * @param alias password alias of form ${ALIAS=xxx}
 * @return real password of ssh user, null if not found
 */
String expandPasswordAlias(String host,String alias,boolean verifyConn){
  String expandedPassword=null;
  boolean connStatus=false;
  try {
    File domainsDirFile=DomainDirs.getDefaultDomainsDir();
    File[] files=domainsDirFile.listFiles(new FileFilter(){
      public boolean accept(      File f){
        return f.isDirectory();
      }
    }
);
    for (    File f : files) {
      System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,f.getAbsolutePath());
      try {
        final PasswordAdapter pa=new PasswordAdapter(null);
        final boolean exists=pa.aliasExists(alias);
        if (exists) {
          String mPass=getMasterPassword(f.getName());
          expandedPassword=new PasswordAdapter(mPass.toCharArray()).getPasswordForAlias(alias);
        }
      }
 catch (      Exception e) {
        if (logger.isLoggable(Level.FINER)) {
          logger.finer(StringUtils.cat("String_Node_Str",alias,e.getMessage()));
        }
        logger.warning(Strings.get("String_Node_Str",f.getName()));
        continue;
      }
      if (expandedPassword != null) {
        SSHLauncher sshL=new SSHLauncher();
        if (host != null) {
          sshpassword=expandedPassword;
          sshL.init(getRemoteUser(),host,getRemotePort(),sshpassword,null,null,logger);
          connStatus=sshL.checkPasswordAuth();
          if (!connStatus) {
            logger.warning(Strings.get("String_Node_Str",f.getName()));
          }
        }
 else {
          sshkeypassphrase=expandedPassword;
          if (verifyConn) {
            sshL.init(getRemoteUser(),hosts[0],getRemotePort(),sshpassword,getSshKeyFile(),sshkeypassphrase,logger);
            connStatus=sshL.checkConnection();
            if (!connStatus) {
              logger.warning(Strings.get("String_Node_Str",f.getName()));
            }
          }
        }
        if (connStatus) {
          break;
        }
      }
    }
  }
 catch (  IOException ioe) {
    if (logger.isLoggable(Level.FINER)) {
      logger.finer(ioe.getMessage());
    }
  }
  return expandedPassword;
}