Program: 138709
Project: 138709
Buggy source:
/** 
 * Method "createDataProvider" create the data provider, the catalogs and the schemas. The created data provider and its related Catalog and Schemas are stored in the DBConnect class. In order to finally serialize them in a file, the method   {@link DBConnect#saveInFiles()} must be called.
 * @param connector the helper for building CWM objects from a connection
 * @param folderProvider contains the path where the file will be stored.
 * @return the data provider
 * @throws SQLException
 * @throws TalendException
 */
public static Connection createDataProvider(DBConnect connector) throws SQLException, TalendException {
  checkConnection(connector);
  Connection dataProvider=getTdDataProvider(connector);
  if (connector.retrieveDeployedSystemInformations()) {
    TdSoftwareSystem softwareSystem=connector.getSoftwareSystem();
    if (softwareSystem != null) {
      ConnectionHelper.setSoftwareSystem(dataProvider,softwareSystem);
    }
  }
  Collection<Catalog> catalogs=getCatalogs(connector);
  Collection<Schema> schemata=getSchemata(connector);
  boolean allAdded=false;
  String dbType=connector.getDbConnectionParameter().getSqlTypeName();
  if (catalogs.isEmpty()) {
    allAdded=ConnectionHelper.addSchemas(schemata,dataProvider);
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + schemata.size() + "String_Node_Str"+ allAdded);
    }
  }
 else {
    allAdded=ConnectionHelper.addCatalogs(catalogs,dataProvider);
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + catalogs.size() + "String_Node_Str"+ allAdded);
    }
  }
  if (log.isInfoEnabled()) {
    log.info(catalogs.size() + "String_Node_Str");
    log.info(schemata.size() + "String_Node_Str");
    if (schemata.size() == 0 && SupportDBUrlType.ORACLEWITHSIDDEFAULTURL.getLanguage().equals(dbType)) {
      throw new TalendException("String_Node_Str");
    }
  }
  if (log.isDebugEnabled()) {
    printInformations(catalogs,schemata);
  }
  if (!ReponsitoryContextBridge.isDefautProject()) {
    EDatabaseTypeName edatabasetypeInstance=EDatabaseTypeName.getTypeFromDisplayName(dbType);
    String product=edatabasetypeInstance.getProduct();
    String additionalParams=((DatabaseConnection)dataProvider).getAdditionalParams();
    if (additionalParams == null) {
      String[] urlSplitArray=((DatabaseConnection)dataProvider).getURL().split("String_Node_Str");
      if (urlSplitArray.length == 2) {
        ((DatabaseConnection)dataProvider).setAdditionalParams(urlSplitArray[1]);
      }
    }
    if (edatabasetypeInstance.isNeedSchema() && edatabasetypeInstance.getSchemaMappingField() == EDatabaseSchemaOrCatalogMapping.Schema && schemata != null) {
      Iterator<Schema> iter=schemata.iterator();
      while (iter.hasNext()) {
        String uischema=iter.next().getName();
        ((DatabaseConnection)dataProvider).setUiSchema(uischema);
        break;
      }
    }
    String dbname=connector.getDbConnectionParameter().getDbName();
    if ((dbname == null || "String_Node_Str".equals(dbname)) && catalogs != null) {
      Iterator<Catalog> iter=catalogs.iterator();
      while (iter.hasNext()) {
        ((DatabaseConnection)dataProvider).setSID(iter.next().getName());
        break;
      }
    }
    String mapping=MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
    if (dataProvider instanceof DatabaseConnection) {
      ((DatabaseConnection)dataProvider).setProductId(product);
      ((DatabaseConnection)dataProvider).setDbmsId(mapping);
      int versionNum=connector.getConnection().getMetaData().getDatabaseMajorVersion();
      String connectionDbType=((DatabaseConnection)dataProvider).getDatabaseType();
      if (connectionDbType == null) {
        connectionDbType=connector.getDbConnectionParameter().getSqlTypeName();
        ((DatabaseConnection)dataProvider).setDatabaseType(connectionDbType);
      }
      List<EDatabaseVersion4Drivers> dbTypeList=EDatabaseVersion4Drivers.indexOfByDbType(connectionDbType);
      if (dbTypeList.size() == 1) {
        ((DatabaseConnection)dataProvider).setDbVersionString(dbTypeList.get(0).getVersionValue());
      }
 else       if (dbTypeList.size() > 1) {
        for (        EDatabaseVersion4Drivers eDatabaseVersion : dbTypeList) {
          String[] strArray=eDatabaseVersion.getVersionValue().split("String_Node_Str");
          if (strArray.length > 1 && strArray[1].startsWith(Integer.toString(versionNum))) {
            ((DatabaseConnection)dataProvider).setDbVersionString(eDatabaseVersion.getVersionValue());
            break;
          }
        }
      }
    }
  }
  return dataProvider;
}

Fixed version (ground truth):
/** 
 * Method "createDataProvider" create the data provider, the catalogs and the schemas. The created data provider and its related Catalog and Schemas are stored in the DBConnect class. In order to finally serialize them in a file, the method   {@link DBConnect#saveInFiles()} must be called.
 * @param connector the helper for building CWM objects from a connection
 * @param folderProvider contains the path where the file will be stored.
 * @return the data provider
 * @throws SQLException
 * @throws TalendException
 */
public static Connection createDataProvider(DBConnect connector) throws SQLException, TalendException {
  checkConnection(connector);
  Connection dataProvider=getTdDataProvider(connector);
  if (connector.retrieveDeployedSystemInformations()) {
    TdSoftwareSystem softwareSystem=connector.getSoftwareSystem();
    if (softwareSystem != null) {
      ConnectionHelper.setSoftwareSystem(dataProvider,softwareSystem);
    }
  }
  Collection<Catalog> catalogs=getCatalogs(connector);
  Collection<Schema> schemata=getSchemata(connector);
  boolean allAdded=false;
  String dbType=connector.getDbConnectionParameter().getSqlTypeName();
  if (catalogs.isEmpty()) {
    allAdded=ConnectionHelper.addSchemas(schemata,dataProvider);
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + schemata.size() + "String_Node_Str"+ allAdded);
    }
  }
 else {
    allAdded=ConnectionHelper.addCatalogs(catalogs,dataProvider);
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + catalogs.size() + "String_Node_Str"+ allAdded);
    }
  }
  if (log.isInfoEnabled()) {
    log.info(catalogs.size() + "String_Node_Str");
    log.info(schemata.size() + "String_Node_Str");
    if (schemata.size() == 0 && SupportDBUrlType.ORACLEWITHSIDDEFAULTURL.getLanguage().equals(dbType)) {
      throw new TalendException("String_Node_Str");
    }
  }
  if (log.isDebugEnabled()) {
    printInformations(catalogs,schemata);
  }
  if (!ReponsitoryContextBridge.isDefautProject()) {
    EDatabaseTypeName edatabasetypeInstance=EDatabaseTypeName.getTypeFromDisplayName(dbType);
    String product=edatabasetypeInstance.getProduct();
    String additionalParams=((DatabaseConnection)dataProvider).getAdditionalParams();
    if (additionalParams == null) {
      ((DatabaseConnection)dataProvider).setAdditionalParams(connector.getDbConnectionParameter().getaDDParameter());
    }
    if (edatabasetypeInstance.isNeedSchema()) {
      if (schemata.size() == 0 && catalogs.size() > 0) {
        schemata=CatalogHelper.getSchemas(SwitchHelpers.CATALOG_SWITCH.doSwitch((CatalogImpl)catalogs.toArray()[0]));
      }
      if (edatabasetypeInstance.getSchemaMappingField() == EDatabaseSchemaOrCatalogMapping.Schema && schemata.size() > 0) {
        Iterator<Schema> iter=schemata.iterator();
        while (iter.hasNext()) {
          String uischema=iter.next().getName();
          ((DatabaseConnection)dataProvider).setUiSchema(uischema);
          break;
        }
      }
    }
    String dbname=connector.getDbConnectionParameter().getDbName();
    if ((dbname == null || "String_Node_Str".equals(dbname)) && catalogs != null) {
      Iterator<Catalog> iter=catalogs.iterator();
      while (iter.hasNext()) {
        ((DatabaseConnection)dataProvider).setSID(iter.next().getName());
        break;
      }
    }
    String mapping=MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
    if (dataProvider instanceof DatabaseConnection) {
      ((DatabaseConnection)dataProvider).setProductId(product);
      ((DatabaseConnection)dataProvider).setDbmsId(mapping);
      int versionNum=connector.getConnection().getMetaData().getDatabaseMajorVersion();
      String connectionDbType=((DatabaseConnection)dataProvider).getDatabaseType();
      if (connectionDbType == null) {
        connectionDbType=connector.getDbConnectionParameter().getSqlTypeName();
        ((DatabaseConnection)dataProvider).setDatabaseType(connectionDbType);
      }
      List<EDatabaseVersion4Drivers> dbTypeList=EDatabaseVersion4Drivers.indexOfByDbType(connectionDbType);
      if (dbTypeList.size() == 1) {
        ((DatabaseConnection)dataProvider).setDbVersionString(dbTypeList.get(0).getVersionValue());
      }
 else       if (dbTypeList.size() > 1) {
        for (        EDatabaseVersion4Drivers eDatabaseVersion : dbTypeList) {
          String[] strArray=eDatabaseVersion.getVersionValue().split("String_Node_Str");
          if (strArray.length > 1 && strArray[1].startsWith(Integer.toString(versionNum))) {
            ((DatabaseConnection)dataProvider).setDbVersionString(eDatabaseVersion.getVersionValue());
            break;
          }
        }
      }
    }
  }
  return dataProvider;
}