Program: 126503
Project: 126503
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 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>();
  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) {
      librairesManagerService.retrieve(driverNames,getJavaLibPath(),new NullProgressMonitor());
      for (      String jar : driverNames) {
        jarPathList.add(getJavaLibPath() + jar);
      }
      driverClassName=getDriverClassByDbType(dbType);
      if (EDatabaseTypeName.VERTICA.getXmlName().equals(dbType) && (EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_5_1.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6_1_X.getVersionValue().equals(dbVersion)|| EDatabaseVersion4Drivers.VERTICA_7.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");
        List<String> jarsToRetreive=new ArrayList<String>();
        for (        String jar : jars) {
          Path path=new Path(jar);
          if (!checkFileCRCCode(new File(getJavaLibPath() + path.lastSegment()),new File(jar))) {
            String librariesPath=getLibrariesPath(ECodeLanguage.JAVA);
            File existJar=new File(librariesPath + File.separator + path.lastSegment());
            if (existJar.exists()) {
              existJar.delete();
              FilesUtils.copyFile(new File(jar),existJar);
            }
          }
          if (jarsAvailable.contains(path.lastSegment())) {
            if (!new File(getJavaLibPath() + path.lastSegment()).exists()) {
              jarsToRetreive.add(path.lastSegment());
            }
            jarPathList.add(getJavaLibPath() + path.lastSegment());
          }
 else {
            jarsToRetreive.add(path.lastSegment());
            jarPathList.add(jar);
          }
        }
        librairesManagerService.retrieve(jarsToRetreive,getJavaLibPath(),new NullProgressMonitor());
      }
 else {
        Path path=new Path(driverJarPathArg);
        File driverFile=new File(driverJarPathArg);
        boolean isExist=driverFile.exists();
        if (!isExist) {
          jarPathList.add("String_Node_Str");
        }
 else {
          jarPathList.add(driverJarPathArg);
        }
      }
    }
 else {
      if (driverJarPathArg.contains("String_Node_Str")) {
        String jars[]=driverJarPathArg.split("String_Node_Str");
        librairesManagerService.retrieve(Arrays.asList(jars),getJavaLibPath(),new NullProgressMonitor());
        for (        String jar : jars) {
          jarPathList.add(getJavaLibPath() + jar);
        }
      }
 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=getDriverClassByDbType(dbType);
    if (dbType.equals(EDatabaseTypeName.ACCESS.getXmlName())) {
      checkAccessDbq(url);
    }
  }
  List list=new ArrayList();
  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 && dbType.equalsIgnoreCase(EDatabaseTypeName.MSSQL.getDisplayName()) && "String_Node_Str".equals(username)) {
    if (DRIVER_CACHE.containsKey(EDatabase4DriverClassName.MSSQL.getDriverClass())) {
      wapperDriver=DRIVER_CACHE.get(EDatabase4DriverClassName.MSSQL.getDriverClass());
      Properties info=new Properties();
      username=username != null ? username : "String_Node_Str";
      pwd=pwd != null ? pwd : "String_Node_Str";
      info.put("String_Node_Str",username);
      info.put("String_Node_Str",pwd);
      connection=wapperDriver.connect(url,info);
    }
 else {
      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();
    if (EDatabaseTypeName.HIVE.getDisplayName().equals(dbType) && "String_Node_Str".equalsIgnoreCase(dbVersion)) {
      loadJarRequiredByDriver(dbType,dbVersion);
    }
    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 {
    try {
      Class<?> klazz=Class.forName(driverClassName);
      Properties info=new Properties();
      info.put("String_Node_Str",username);
      info.put("String_Node_Str",pwd);
      if (dbType.equals(EDatabaseTypeName.ACCESS.getXmlName()) || dbType.equals(EDatabaseTypeName.GODBC.getXmlName())) {
        Charset systemCharset=CharsetToolkit.getInternalSystemCharset();
        if (systemCharset != null && systemCharset.displayName() != null) {
          info.put("String_Node_Str",systemCharset.displayName());
        }
      }
      connection=((Driver)klazz.newInstance()).connect(url,info);
    }
 catch (    ClassNotFoundException e) {
      String errorMessage=Messages.getString("String_Node_Str") + driverClassName;
      if (driverJarPath != null && driverJarPath.length > 0) {
        errorMessage=errorMessage + "String_Node_Str" + Messages.getString("String_Node_Str");
        for (        String jarName : driverJarPath) {
          errorMessage=errorMessage + "String_Node_Str" + new Path(jarName).lastSegment();
        }
      }
      throw new MissingDriverException(errorMessage);
    }
  }
  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 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>();
  ILibraryManagerService librairesManagerService=(ILibraryManagerService)GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
  if (librairesManagerService != null) {
    if ((driverJarPathArg == null || driverJarPathArg.equals("String_Node_Str"))) {
      List<String> driverNames=EDatabaseVersion4Drivers.getDrivers(dbType,dbVersion);
      if (driverNames != null) {
        librairesManagerService.retrieve(driverNames,getJavaLibPath(),new NullProgressMonitor());
        for (        String jar : driverNames) {
          jarPathList.add(getJavaLibPath() + jar);
        }
        driverClassName=getDriverClassByDbType(dbType);
        if (EDatabaseTypeName.VERTICA.getXmlName().equals(dbType) && (EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_5_1.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6_1_X.getVersionValue().equals(dbVersion)|| EDatabaseVersion4Drivers.VERTICA_7.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");
          List<String> jarsToRetreive=new ArrayList<String>();
          for (          String jar : jars) {
            Path path=new Path(jar);
            if (!checkFileCRCCode(new File(getJavaLibPath() + path.lastSegment()),new File(jar))) {
              String librariesPath=getLibrariesPath(ECodeLanguage.JAVA);
              File existJar=new File(librariesPath + File.separator + path.lastSegment());
              if (existJar.exists()) {
                existJar.delete();
                FilesUtils.copyFile(new File(jar),existJar);
              }
            }
            if (jarsAvailable.contains(path.lastSegment())) {
              if (!new File(getJavaLibPath() + path.lastSegment()).exists()) {
                jarsToRetreive.add(path.lastSegment());
              }
              jarPathList.add(getJavaLibPath() + path.lastSegment());
            }
 else {
              jarsToRetreive.add(path.lastSegment());
              jarPathList.add(jar);
            }
          }
          librairesManagerService.retrieve(jarsToRetreive,getJavaLibPath(),new NullProgressMonitor());
        }
 else {
          Path path=new Path(driverJarPathArg);
          File driverFile=new File(driverJarPathArg);
          boolean isExist=driverFile.exists();
          if (!isExist) {
            jarPathList.add("String_Node_Str");
          }
 else {
            jarPathList.add(driverJarPathArg);
          }
        }
      }
 else {
        if (driverJarPathArg.contains("String_Node_Str")) {
          String jars[]=driverJarPathArg.split("String_Node_Str");
          librairesManagerService.retrieve(Arrays.asList(jars),getJavaLibPath(),new NullProgressMonitor());
          for (          String jar : jars) {
            jarPathList.add(getJavaLibPath() + jar);
          }
        }
 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=getDriverClassByDbType(dbType);
    if (dbType.equals(EDatabaseTypeName.ACCESS.getXmlName())) {
      checkAccessDbq(url);
    }
  }
  List list=new ArrayList();
  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 && dbType.equalsIgnoreCase(EDatabaseTypeName.MSSQL.getDisplayName()) && "String_Node_Str".equals(username)) {
    if (DRIVER_CACHE.containsKey(EDatabase4DriverClassName.MSSQL.getDriverClass())) {
      wapperDriver=DRIVER_CACHE.get(EDatabase4DriverClassName.MSSQL.getDriverClass());
      Properties info=new Properties();
      username=username != null ? username : "String_Node_Str";
      pwd=pwd != null ? pwd : "String_Node_Str";
      info.put("String_Node_Str",username);
      info.put("String_Node_Str",pwd);
      connection=wapperDriver.connect(url,info);
    }
 else {
      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();
    if (EDatabaseTypeName.HIVE.getDisplayName().equals(dbType) && "String_Node_Str".equalsIgnoreCase(dbVersion)) {
      loadJarRequiredByDriver(dbType,dbVersion);
    }
    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 {
    try {
      Class<?> klazz=Class.forName(driverClassName);
      Properties info=new Properties();
      info.put("String_Node_Str",username);
      info.put("String_Node_Str",pwd);
      if (dbType.equals(EDatabaseTypeName.ACCESS.getXmlName()) || dbType.equals(EDatabaseTypeName.GODBC.getXmlName())) {
        Charset systemCharset=CharsetToolkit.getInternalSystemCharset();
        if (systemCharset != null && systemCharset.displayName() != null) {
          info.put("String_Node_Str",systemCharset.displayName());
        }
      }
      connection=((Driver)klazz.newInstance()).connect(url,info);
    }
 catch (    ClassNotFoundException e) {
      String errorMessage=Messages.getString("String_Node_Str") + driverClassName;
      if (driverJarPath != null && driverJarPath.length > 0) {
        errorMessage=errorMessage + "String_Node_Str" + Messages.getString("String_Node_Str");
        for (        String jarName : driverJarPath) {
          errorMessage=errorMessage + "String_Node_Str" + new Path(jarName).lastSegment();
        }
      }
      throw new MissingDriverException(errorMessage);
    }
  }
  if (connection == null) {
    throw new Exception(Messages.getString("String_Node_Str"));
  }
  conList.add(connection);
  if (wapperDriver != null) {
    conList.add(wapperDriver);
  }
  return conList;
}