Program: 128864
Project: 128864
Buggy source:
/** 
 * DOC xye Comment method "connect".
 * @param dbType
 * @param url
 * @param username
 * @param pwd
 * @param driverClassName
 * @param driverJarPath
 * @param dbVersionString
 * @return
 * @throws Exception
 */
public static List connect(String dbType,String url,String username,String pwd,final String driverClassNameArg,final String driverJarPathArg,String dbVersion,String additionalParams) throws Exception {
  Connection connection=null;
  DriverShim wapperDriver=null;
  List conList=new ArrayList();
  String driverClassName=driverClassNameArg;
  List<String> jarPathList=new ArrayList<String>();
  if (PluginChecker.isOnlyTopLoaded()) {
    if (StringUtils.isBlank(driverClassName)) {
      driverClassName=ExtractMetaDataUtils.getDriverClassByDbType(dbType);
    }
    IMetadataConnection mconn=new MetadataConnection();
    mconn.setUrl(url);
    mconn.setUsername(username);
    mconn.setPassword(pwd);
    mconn.setDbType(dbType);
    mconn.setDriverClass(driverClassName);
    mconn.setDriverJarPath(driverJarPathArg);
    mconn.setDbVersionString(dbVersion);
    mconn.setAdditionalParams(additionalParams);
    TypedReturnCode<Connection> checkConnection=MetadataConnectionUtils.checkConnection(mconn);
    if (checkConnection.isOk()) {
      conList.add(checkConnection.getObject());
    }
 else {
      throw new Exception(checkConnection.getMessage());
    }
  }
 else {
    ILibraryManagerService librairesManagerService=(ILibraryManagerService)GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
    if ((driverJarPathArg == null || driverJarPathArg.equals("String_Node_Str"))) {
      List<String> driverNames=EDatabaseVersion4Drivers.getDrivers(dbType,dbVersion);
      if (driverNames != null) {
        for (        String jar : driverNames) {
          if (!new File(getJavaLibPath() + jar).exists()) {
            librairesManagerService.retrieve(jar,getJavaLibPath(),new NullProgressMonitor());
          }
          jarPathList.add(getJavaLibPath() + jar);
        }
        driverClassName=ExtractMetaDataUtils.getDriverClassByDbType(dbType);
        if (EDatabaseTypeName.VERTICA.getXmlName().equals(dbType) && EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion)) {
          driverClassName=EDatabase4DriverClassName.VERTICA2.getDriverClass();
        }
      }
    }
 else {
      Set<String> jarsAvailable=librairesManagerService.list(new NullProgressMonitor());
      if (driverJarPathArg.contains("String_Node_Str") || driverJarPathArg.startsWith("String_Node_Str")) {
        if (driverJarPathArg.contains("String_Node_Str")) {
          String jars[]=driverJarPathArg.split("String_Node_Str");
          for (          String jar : jars) {
            Path path=new Path(jar);
            if (jarsAvailable.contains(path.lastSegment())) {
              if (!new File(getJavaLibPath() + path.lastSegment()).exists()) {
                librairesManagerService.retrieve(path.lastSegment(),getJavaLibPath(),new NullProgressMonitor());
              }
              jarPathList.add(getJavaLibPath() + path.lastSegment());
            }
 else {
              jarPathList.add(jar);
            }
          }
        }
 else {
          Path path=new Path(driverJarPathArg);
          if (jarsAvailable.contains(path.lastSegment())) {
            String jarUnderLib=getJavaLibPath() + path.lastSegment();
            File file=new File(jarUnderLib);
            if (!file.exists()) {
              librairesManagerService.retrieve(path.lastSegment(),getJavaLibPath(),new NullProgressMonitor());
            }
            jarPathList.add(jarUnderLib);
          }
 else {
            jarPathList.add(driverJarPathArg);
          }
        }
      }
 else {
        if (driverJarPathArg.contains("String_Node_Str")) {
          String jars[]=driverJarPathArg.split("String_Node_Str");
          for (int i=0; i < jars.length; i++) {
            if (!new File(getJavaLibPath() + jars[i]).exists()) {
              librairesManagerService.retrieve(jars[i],getJavaLibPath(),new NullProgressMonitor());
            }
            jarPathList.add(getJavaLibPath() + jars[i]);
          }
        }
 else {
          if (!new File(getJavaLibPath() + driverJarPathArg).exists()) {
            librairesManagerService.retrieve(driverJarPathArg,getJavaLibPath(),new NullProgressMonitor());
          }
          jarPathList.add(getJavaLibPath() + driverJarPathArg);
        }
      }
    }
    final String[] driverJarPath=jarPathList.toArray(new String[0]);
    if (driverClassName == null || driverClassName.equals("String_Node_Str")) {
      driverClassName=ExtractMetaDataUtils.getDriverClassByDbType(dbType);
      if (dbType.equals(EDatabaseTypeName.ACCESS.getXmlName())) {
        ExtractMetaDataUtils.checkAccessDbq(url);
      }
    }
    List list=new ArrayList();
    ExtractMetaDataUtils.checkDBConnectionTimeout();
    if (dbType != null && dbType.equalsIgnoreCase(EDatabaseTypeName.GENERAL_JDBC.getXmlName())) {
      JDBCDriverLoader loader=new JDBCDriverLoader();
      list=loader.getConnection(driverJarPath,driverClassName,url,username,pwd,dbType,dbVersion,additionalParams);
      if (list != null && list.size() > 0) {
        for (int i=0; i < list.size(); i++) {
          if (list.get(i) instanceof Connection) {
            connection=(Connection)list.get(i);
          }
          if (list.get(i) instanceof DriverShim) {
            wapperDriver=(DriverShim)list.get(i);
          }
        }
      }
    }
 else     if (dbType != null && (isValidJarFile(driverJarPath) || dbType.equalsIgnoreCase(EDatabaseTypeName.GODBC.getXmlName()))) {
      JDBCDriverLoader loader=new JDBCDriverLoader();
      list=loader.getConnection(driverJarPath,driverClassName,url,username,pwd,dbType,dbVersion,additionalParams);
      if (list != null && list.size() > 0) {
        for (int i=0; i < list.size(); i++) {
          if (list.get(i) instanceof Connection) {
            connection=(Connection)list.get(i);
          }
          if (list.get(i) instanceof DriverShim) {
            wapperDriver=(DriverShim)list.get(i);
          }
        }
      }
    }
 else {
      Class<?> klazz=Class.forName(driverClassName);
      Properties info=new Properties();
      info.put("String_Node_Str",username);
      info.put("String_Node_Str",pwd);
      connection=((Driver)klazz.newInstance()).connect(url,info);
    }
    if (connection == null) {
      throw new Exception(Messages.getString("String_Node_Str"));
    }
    conList.add(connection);
    if (wapperDriver != null) {
      conList.add(wapperDriver);
    }
  }
  return conList;
}

Fixed version (ground truth):
/** 
 * DOC xye Comment method "connect".
 * @param dbType
 * @param url
 * @param username
 * @param pwd
 * @param driverClassName
 * @param driverJarPath
 * @param dbVersionString
 * @return
 * @throws Exception
 */
public static List connect(String dbType,String url,String username,String pwd,final String driverClassNameArg,final String driverJarPathArg,String dbVersion,String additionalParams) throws Exception {
  Connection connection=null;
  DriverShim wapperDriver=null;
  List conList=new ArrayList();
  String driverClassName=driverClassNameArg;
  List<String> jarPathList=new ArrayList<String>();
  if (PluginChecker.isOnlyTopLoaded()) {
    if (StringUtils.isBlank(driverClassName)) {
      driverClassName=ExtractMetaDataUtils.getDriverClassByDbType(dbType);
    }
    IMetadataConnection mconn=new MetadataConnection();
    mconn.setUrl(url);
    mconn.setUsername(username);
    mconn.setPassword(pwd);
    mconn.setDbType(dbType);
    mconn.setDriverClass(driverClassName);
    mconn.setDriverJarPath(driverJarPathArg);
    mconn.setDbVersionString(dbVersion);
    mconn.setAdditionalParams(additionalParams);
    TypedReturnCode<Connection> checkConnection=MetadataConnectionUtils.checkConnection(mconn);
    if (checkConnection.isOk()) {
      conList.add(checkConnection.getObject());
    }
 else {
      throw new Exception(checkConnection.getMessage());
    }
  }
 else {
    ILibraryManagerService librairesManagerService=(ILibraryManagerService)GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
    if ((driverJarPathArg == null || driverJarPathArg.equals("String_Node_Str"))) {
      List<String> driverNames=EDatabaseVersion4Drivers.getDrivers(dbType,dbVersion);
      if (driverNames != null) {
        for (        String jar : driverNames) {
          if (!new File(getJavaLibPath() + jar).exists()) {
            librairesManagerService.retrieve(jar,getJavaLibPath(),new NullProgressMonitor());
          }
          jarPathList.add(getJavaLibPath() + jar);
        }
        driverClassName=ExtractMetaDataUtils.getDriverClassByDbType(dbType);
        if (EDatabaseTypeName.VERTICA.getXmlName().equals(dbType) && EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion)) {
          driverClassName=EDatabase4DriverClassName.VERTICA2.getDriverClass();
        }
      }
    }
 else {
      Set<String> jarsAvailable=librairesManagerService.list(new NullProgressMonitor());
      if (driverJarPathArg.contains("String_Node_Str") || driverJarPathArg.startsWith("String_Node_Str")) {
        if (driverJarPathArg.contains("String_Node_Str")) {
          String jars[]=driverJarPathArg.split("String_Node_Str");
          for (          String jar : jars) {
            Path path=new Path(jar);
            if (jarsAvailable.contains(path.lastSegment())) {
              if (!new File(getJavaLibPath() + path.lastSegment()).exists()) {
                librairesManagerService.retrieve(path.lastSegment(),getJavaLibPath(),new NullProgressMonitor());
              }
              jarPathList.add(getJavaLibPath() + path.lastSegment());
            }
 else {
              jarPathList.add(jar);
            }
          }
        }
 else {
          Path path=new Path(driverJarPathArg);
          if (jarsAvailable.contains(path.lastSegment())) {
            String jarUnderLib=getJavaLibPath() + path.lastSegment();
            File file=new File(jarUnderLib);
            if (!file.exists()) {
              librairesManagerService.retrieve(path.lastSegment(),getJavaLibPath(),new NullProgressMonitor());
            }
            jarPathList.add(jarUnderLib);
          }
 else {
            jarPathList.add(driverJarPathArg);
          }
        }
      }
 else {
        if (driverJarPathArg.contains("String_Node_Str")) {
          String jars[]=driverJarPathArg.split("String_Node_Str");
          for (int i=0; i < jars.length; i++) {
            if (!new File(getJavaLibPath() + jars[i]).exists()) {
              librairesManagerService.retrieve(jars[i],getJavaLibPath(),new NullProgressMonitor());
            }
            jarPathList.add(getJavaLibPath() + jars[i]);
          }
        }
 else {
          if (!new File(getJavaLibPath() + driverJarPathArg).exists()) {
            librairesManagerService.retrieve(driverJarPathArg,getJavaLibPath(),new NullProgressMonitor());
          }
          jarPathList.add(getJavaLibPath() + driverJarPathArg);
        }
      }
    }
    final String[] driverJarPath=jarPathList.toArray(new String[0]);
    if (driverClassName == null || driverClassName.equals("String_Node_Str")) {
      driverClassName=ExtractMetaDataUtils.getDriverClassByDbType(dbType);
      if (dbType.equals(EDatabaseTypeName.ACCESS.getXmlName())) {
        ExtractMetaDataUtils.checkAccessDbq(url);
      }
    }
    List list=new ArrayList();
    ExtractMetaDataUtils.checkDBConnectionTimeout();
    if (dbType != null && dbType.equalsIgnoreCase(EDatabaseTypeName.GENERAL_JDBC.getXmlName())) {
      JDBCDriverLoader loader=new JDBCDriverLoader();
      list=loader.getConnection(driverJarPath,driverClassName,url,username,pwd,dbType,dbVersion,additionalParams);
      if (list != null && list.size() > 0) {
        for (int i=0; i < list.size(); i++) {
          if (list.get(i) instanceof Connection) {
            connection=(Connection)list.get(i);
          }
          if (list.get(i) instanceof DriverShim) {
            wapperDriver=(DriverShim)list.get(i);
          }
        }
      }
    }
 else     if (dbType != null && (isValidJarFile(driverJarPath) || dbType.equalsIgnoreCase(EDatabaseTypeName.GODBC.getXmlName()))) {
      JDBCDriverLoader loader=new JDBCDriverLoader();
      list=loader.getConnection(driverJarPath,driverClassName,url,username,pwd,dbType,dbVersion,additionalParams);
      if (list != null && list.size() > 0) {
        for (int i=0; i < list.size(); i++) {
          if (list.get(i) instanceof Connection) {
            connection=(Connection)list.get(i);
          }
          if (list.get(i) instanceof DriverShim) {
            wapperDriver=(DriverShim)list.get(i);
          }
        }
      }
    }
 else {
      Class<?> klazz=Class.forName(driverClassName);
      Properties info=new Properties();
      info.put("String_Node_Str",username);
      info.put("String_Node_Str",pwd);
      Charset systemCharset=CharsetToolkit.getInternalSystemCharset();
      if (systemCharset != null && systemCharset.displayName() != null) {
        info.put("String_Node_Str",systemCharset.displayName());
      }
      connection=((Driver)klazz.newInstance()).connect(url,info);
    }
    if (connection == null) {
      throw new Exception(Messages.getString("String_Node_Str"));
    }
    conList.add(connection);
    if (wapperDriver != null) {
      conList.add(wapperDriver);
    }
  }
  return conList;
}