Program: 176584
Project: 176584
Buggy source:
/** 
 * Switch over persistence units.
 * @param entityPuCol the entity pu col
 * @throws SchemaDisagreementException
 * @throws TimedOutException
 * @throws UnavailableException
 * @throws InvalidRequestException
 * @throws TException
 * @throws IOException
 */
protected void switchPersistenceUnits(Map<Class,String> entityPuCol) throws IOException, TException, InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException {
  if (entityPuCol != null) {
    Iterator<Class> iter=entityPuCol.keySet().iterator();
    log.warn("String_Node_Str");
    while (iter.hasNext()) {
      Class clazz=iter.next();
      String pu=entityPuCol.get(clazz);
      Map<String,Metamodel> metaModels=KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodelMap();
      EntityMetadata mAdd=KunderaMetadataManager.getEntityMetadata(clazz);
      for (      Metamodel m : metaModels.values()) {
        mAdd=((MetamodelImpl)m).getEntityMetadataMap().get(clazz);
        if (mAdd != null) {
          break;
        }
      }
      mAdd.setPersistenceUnit(pu);
      Map<String,List<String>> clazzToPu=new HashMap<String,List<String>>(1);
      List<String> pus=new ArrayList<String>(1);
      pus.add(pu);
      clazzToPu.put(clazz.getName(),pus);
      KunderaMetadata.INSTANCE.getApplicationMetadata().setClazzToPuMap(clazzToPu);
      Metamodel metaModel=KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(pu);
      ((MetamodelImpl)metaModel).addEntityMetadata(clazz,mAdd);
      KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodelMap().put(pu,metaModel);
      PersistenceUnitMetadata puMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata().getPersistenceUnitMetadata(pu);
      String client=puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_CLIENT_FACTORY);
      if (client.equalsIgnoreCase("String_Node_Str") || client.equalsIgnoreCase("String_Node_Str")) {
        if (RUN_IN_EMBEDDED_MODE) {
          CassandraCli.cassandraSetUp();
          CassandraCli.initClient();
        }
        if (AUTO_MANAGE_SCHEMA) {
          if (mAdd.getTableName().equalsIgnoreCase("String_Node_Str")) {
            loadDataForHABITAT();
          }
 else           if (mAdd.getTableName().equalsIgnoreCase("String_Node_Str")) {
            loadDataForPERSONNEL();
          }
        }
      }
      if (client.equalsIgnoreCase("String_Node_Str") && RUN_IN_EMBEDDED_MODE) {
        if (!HBaseCli.isStarted()) {
        }
      }
      if (client.equalsIgnoreCase("String_Node_Str")) {
        try {
          createSchemaForPERSONNEL();
          createSchemaForHABITAT();
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
      }
      String schema=puMetadata.getProperty(PersistenceProperties.KUNDERA_KEYSPACE);
      mAdd.setSchema(schema != null ? schema : KEYSPACE);
      log.warn("String_Node_Str" + pu + "String_Node_Str"+ clazz.getCanonicalName());
    }
  }
  dao.closeEntityManager();
  em=dao.getEntityManager(persistenceUnits,propertyMap);
}

Fixed version (ground truth):
/** 
 * Switch over persistence units.
 * @param entityPuCol the entity pu col
 * @throws SchemaDisagreementException
 * @throws TimedOutException
 * @throws UnavailableException
 * @throws InvalidRequestException
 * @throws TException
 * @throws IOException
 */
protected void switchPersistenceUnits(Map<Class,String> entityPuCol) throws IOException, TException, InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException {
  if (entityPuCol != null) {
    Iterator<Class> iter=entityPuCol.keySet().iterator();
    log.warn("String_Node_Str");
    while (iter.hasNext()) {
      Class clazz=iter.next();
      String pu=entityPuCol.get(clazz);
      Map<String,Metamodel> metaModels=KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodelMap();
      EntityMetadata mAdd=KunderaMetadataManager.getEntityMetadata(clazz);
      for (      Metamodel m : metaModels.values()) {
        mAdd=((MetamodelImpl)m).getEntityMetadataMap().get(clazz);
        if (mAdd != null) {
          break;
        }
      }
      mAdd.setPersistenceUnit(pu);
      Map<String,List<String>> clazzToPu=new HashMap<String,List<String>>(1);
      List<String> pus=new ArrayList<String>(1);
      pus.add(pu);
      clazzToPu.put(clazz.getName(),pus);
      KunderaMetadata.INSTANCE.getApplicationMetadata().setClazzToPuMap(clazzToPu);
      Metamodel metaModel=KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(pu);
      ((MetamodelImpl)metaModel).addEntityMetadata(clazz,mAdd);
      KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodelMap().put(pu,metaModel);
      PersistenceUnitMetadata puMetadata=KunderaMetadata.INSTANCE.getApplicationMetadata().getPersistenceUnitMetadata(pu);
      String client=puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_CLIENT_FACTORY);
      if (client.equalsIgnoreCase("String_Node_Str") || client.equalsIgnoreCase("String_Node_Str")) {
        if (RUN_IN_EMBEDDED_MODE) {
          CassandraCli.cassandraSetUp();
          CassandraCli.initClient();
        }
        if (AUTO_MANAGE_SCHEMA) {
          if (mAdd.getTableName().equalsIgnoreCase("String_Node_Str")) {
            loadDataForHABITAT();
          }
 else           if (mAdd.getTableName().equalsIgnoreCase("String_Node_Str")) {
            loadDataForPERSONNEL();
          }
        }
      }
      if (client.equalsIgnoreCase("String_Node_Str") && RUN_IN_EMBEDDED_MODE) {
      }
      if (client.equalsIgnoreCase("String_Node_Str")) {
        try {
          createSchemaForPERSONNEL();
          createSchemaForHABITAT();
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
      }
      String schema=puMetadata.getProperty(PersistenceProperties.KUNDERA_KEYSPACE);
      mAdd.setSchema(schema != null ? schema : KEYSPACE);
      log.warn("String_Node_Str" + pu + "String_Node_Str"+ clazz.getCanonicalName());
    }
  }
  dao.closeEntityManager();
  em=dao.getEntityManager(persistenceUnits,propertyMap);
}