Program: 63259
Project: 63259
Buggy source:
/** 
 * test setup -uses existing connection to obtain DB info - username, pwd and connection string/schema name -creates new DB schema named '$existingSchema+"_MT"' -creates 2 data sources (first points to original schema, second to the newly created one) and 1 proxy datasource (wraps original DSs and all DB requests are going through this DS) -prepares tables in both DSs through the usage of proxy DS -stores properties necessary for proper EMF creation in emfProperties field
 */
public void testSetup(){
  if (!getPlatform().isMySQL()) {
    warning("String_Node_Str");
    return;
  }
  DatabaseSessionImpl databaseSession=getDatabaseSession();
  DatabaseLogin login=getDatabaseSession().getLogin();
  schema1=login.getConnectionString().substring(login.getConnectionString().lastIndexOf('/') + 1);
  schema2=schema1 + "String_Node_Str";
  assertNotNull(schema1);
  assertNotNull(schema2);
  databaseSession.executeNonSelectingSQL("String_Node_Str" + schema1 + "String_Node_Str");
  try {
    databaseSession.executeNonSelectingSQL("String_Node_Str" + schema2 + "String_Node_Str");
  }
 catch (  Throwable t) {
  }
  try {
    databaseSession.executeNonSelectingSQL("String_Node_Str" + schema2 + "String_Node_Str");
  }
 catch (  Throwable t) {
    skipTest=true;
    warning("String_Node_Str");
    databaseSession.logThrowable(SessionLog.WARNING,SessionLog.CONNECTION,t);
    return;
  }
 finally {
    databaseSession.logout();
  }
  Map<String,String> currentProps=JUnitTestCaseHelper.getDatabaseProperties(getPersistenceUnitName());
  TestDataSource ds1=new TestDataSource(login.getDriverClassName(),login.getConnectionString(),(Properties)login.getProperties().clone());
  TestDataSource ds2=new TestDataSource(login.getDriverClassName(),login.getConnectionString() + "String_Node_Str",(Properties)login.getProperties().clone());
  proxyDataSource=new ProxyDS(databaseSession,currentProps.get(PersistenceUnitProperties.JDBC_USER),currentProps.get(PersistenceUnitProperties.JDBC_PASSWORD));
  proxyDataSource.add(schema1,ds1);
  proxyDataSource.add(schema2,ds2);
  emfProperties=new Properties();
  emfProperties.putAll(currentProps);
  emfProperties.remove(PersistenceUnitProperties.JDBC_DRIVER);
  emfProperties.remove(PersistenceUnitProperties.JDBC_USER);
  emfProperties.remove(PersistenceUnitProperties.JDBC_URL);
  emfProperties.remove(PersistenceUnitProperties.JDBC_PASSWORD);
  emfProperties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE,proxyDataSource);
  emfProperties.put(PersistenceUnitProperties.DDL_GENERATION,PersistenceUnitProperties.NONE);
  emfProperties.put(PersistenceUnitProperties.MULTITENANT_STRATEGY,"String_Node_Str");
  proxyDataSource.setCurrentDS(schema1);
  EntityManagerFactory emf=Persistence.createEntityManagerFactory(getPersistenceUnitName(),emfProperties);
  assertNotNull(emf);
  new AdvancedTableCreator().replaceTables(((EntityManagerFactoryImpl)emf).getServerSession());
  emf.close();
  proxyDataSource.setCurrentDS(schema2);
  emf=Persistence.createEntityManagerFactory(getPersistenceUnitName(),emfProperties);
  assertNotNull(emf);
  new AdvancedTableCreator().replaceTables(((EntityManagerFactoryImpl)emf).getServerSession());
  emf.close();
}

Fixed version (ground truth):
/** 
 * test setup -uses existing connection to obtain DB info - username, pwd and connection string/schema name -creates new DB schema named '$existingSchema+"_MT"' -creates 2 data sources (first points to original schema, second to the newly created one) and 1 proxy datasource (wraps original DSs and all DB requests are going through this DS) -prepares tables in both DSs through the usage of proxy DS -stores properties necessary for proper EMF creation in emfProperties field
 */
public void testSetup(){
  if (!getPlatform().isMySQL()) {
    warning("String_Node_Str");
    return;
  }
  DatabaseSessionImpl databaseSession=getDatabaseSession();
  DatabaseLogin login=getDatabaseSession().getLogin();
  String connectionString=login.getConnectionString();
  int schemaIdx=connectionString.lastIndexOf('/');
  int queryIdx=connectionString.indexOf('?',schemaIdx);
  schema1=connectionString.substring(schemaIdx + 1,queryIdx < 0 ? connectionString.length() : queryIdx);
  schema2=schema1 + "String_Node_Str";
  String connectionStringMT=queryIdx < 0 ? connectionString + "String_Node_Str" : connectionString.substring(0,queryIdx) + "String_Node_Str" + connectionString.substring(queryIdx);
  assertNotNull(schema1);
  assertNotNull(schema2);
  databaseSession.executeNonSelectingSQL("String_Node_Str" + schema1 + "String_Node_Str");
  try {
    databaseSession.executeNonSelectingSQL("String_Node_Str" + schema2 + "String_Node_Str");
  }
 catch (  Throwable t) {
  }
  try {
    databaseSession.executeNonSelectingSQL("String_Node_Str" + schema2 + "String_Node_Str");
  }
 catch (  Throwable t) {
    skipTest=true;
    warning("String_Node_Str");
    databaseSession.logThrowable(SessionLog.WARNING,SessionLog.CONNECTION,t);
    return;
  }
 finally {
    databaseSession.logout();
  }
  Map<String,String> currentProps=JUnitTestCaseHelper.getDatabaseProperties(getPersistenceUnitName());
  TestDataSource ds1=new TestDataSource(login.getDriverClassName(),connectionString,(Properties)login.getProperties().clone());
  TestDataSource ds2=new TestDataSource(login.getDriverClassName(),connectionStringMT,(Properties)login.getProperties().clone());
  proxyDataSource=new ProxyDS(databaseSession,currentProps.get(PersistenceUnitProperties.JDBC_USER),currentProps.get(PersistenceUnitProperties.JDBC_PASSWORD));
  proxyDataSource.add(schema1,ds1);
  proxyDataSource.add(schema2,ds2);
  emfProperties=new Properties();
  emfProperties.putAll(currentProps);
  emfProperties.remove(PersistenceUnitProperties.JDBC_DRIVER);
  emfProperties.remove(PersistenceUnitProperties.JDBC_USER);
  emfProperties.remove(PersistenceUnitProperties.JDBC_URL);
  emfProperties.remove(PersistenceUnitProperties.JDBC_PASSWORD);
  emfProperties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE,proxyDataSource);
  emfProperties.put(PersistenceUnitProperties.DDL_GENERATION,PersistenceUnitProperties.NONE);
  emfProperties.put(PersistenceUnitProperties.MULTITENANT_STRATEGY,"String_Node_Str");
  proxyDataSource.setCurrentDS(schema1);
  EntityManagerFactory emf=Persistence.createEntityManagerFactory(getPersistenceUnitName(),emfProperties);
  assertNotNull(emf);
  new AdvancedTableCreator().replaceTables(((EntityManagerFactoryImpl)emf).getServerSession());
  emf.close();
  proxyDataSource.setCurrentDS(schema2);
  emf=Persistence.createEntityManagerFactory(getPersistenceUnitName(),emfProperties);
  assertNotNull(emf);
  new AdvancedTableCreator().replaceTables(((EntityManagerFactoryImpl)emf).getServerSession());
  emf.close();
}