Program: 63433
Project: 63433
Buggy source:
private EntityManagerFactory createContainerEntityManagerFactoryImpl(PersistenceUnitInfo info,Map properties,boolean requiresConnection){
  JavaSECMPInitializer.setIsInContainer(true);
  Map nonNullProperties=(properties == null) ? new HashMap() : properties;
  EntityManagerSetupImpl emSetupImpl=null;
  if (EntityManagerSetupImpl.mustBeCompositeMember(info)) {
    emSetupImpl=new EntityManagerSetupImpl(info.getPersistenceUnitName(),info.getPersistenceUnitName());
    emSetupImpl.predeploy(info,nonNullProperties);
  }
 else {
    boolean isNew=false;
    ClassTransformer transformer=null;
    String uniqueName=PersistenceUnitProcessor.buildPersistenceUnitName(info.getPersistenceUnitRootUrl(),info.getPersistenceUnitName());
    String sessionName=EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties,info,uniqueName);
synchronized (EntityManagerFactoryProvider.emSetupImpls) {
      emSetupImpl=EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
      if (emSetupImpl == null) {
        emSetupImpl=new EntityManagerSetupImpl(uniqueName,sessionName);
        isNew=true;
        emSetupImpl.setIsInContainerMode(true);
        transformer=emSetupImpl.predeploy(info,nonNullProperties);
        EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName,emSetupImpl);
      }
    }
    if (!isNew) {
      if (!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
        throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName,uniqueName,emSetupImpl.getPersistenceUnitUniqueName());
      }
      boolean undeployed=false;
synchronized (emSetupImpl) {
        if (emSetupImpl.isUndeployed()) {
          undeployed=true;
        }
 else {
          transformer=emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(),nonNullProperties);
        }
      }
      if (undeployed) {
        return createContainerEntityManagerFactory(info,properties);
      }
    }
    if (transformer != null) {
      info.addTransformer(transformer);
    }
  }
  EntityManagerFactoryImpl factory=null;
  try {
    factory=new EntityManagerFactoryImpl(emSetupImpl,nonNullProperties);
    emSetupImpl.setRequiresConnection(requiresConnection);
    emSetupImpl.preInitializeCanonicalMetamodel(factory);
    if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
      factory.getDatabaseSession();
    }
    return factory;
  }
 catch (  RuntimeException ex) {
    if (factory != null) {
      factory.close();
    }
 else {
      emSetupImpl.undeploy();
    }
    throw ex;
  }
}

Fixed version (ground truth):
protected EntityManagerFactory createContainerEntityManagerFactoryImpl(PersistenceUnitInfo info,Map properties,boolean requiresConnection){
  JavaSECMPInitializer.setIsInContainer(true);
  Map nonNullProperties=(properties == null) ? new HashMap() : properties;
  EntityManagerSetupImpl emSetupImpl=null;
  if (EntityManagerSetupImpl.mustBeCompositeMember(info)) {
    emSetupImpl=new EntityManagerSetupImpl(info.getPersistenceUnitName(),info.getPersistenceUnitName());
    emSetupImpl.predeploy(info,nonNullProperties);
  }
 else {
    boolean isNew=false;
    ClassTransformer transformer=null;
    String uniqueName=PersistenceUnitProcessor.buildPersistenceUnitName(info.getPersistenceUnitRootUrl(),info.getPersistenceUnitName());
    String sessionName=EntityManagerSetupImpl.getOrBuildSessionName(nonNullProperties,info,uniqueName);
synchronized (EntityManagerFactoryProvider.emSetupImpls) {
      emSetupImpl=EntityManagerFactoryProvider.getEntityManagerSetupImpl(sessionName);
      if (emSetupImpl == null) {
        emSetupImpl=new EntityManagerSetupImpl(uniqueName,sessionName);
        isNew=true;
        emSetupImpl.setIsInContainerMode(true);
        transformer=emSetupImpl.predeploy(info,nonNullProperties);
        EntityManagerFactoryProvider.addEntityManagerSetupImpl(sessionName,emSetupImpl);
      }
    }
    if (!isNew) {
      if (!uniqueName.equals(emSetupImpl.getPersistenceUnitUniqueName())) {
        throw PersistenceUnitLoadingException.sessionNameAlreadyInUse(sessionName,uniqueName,emSetupImpl.getPersistenceUnitUniqueName());
      }
      boolean undeployed=false;
synchronized (emSetupImpl) {
        if (emSetupImpl.isUndeployed()) {
          undeployed=true;
        }
 else {
          transformer=emSetupImpl.predeploy(emSetupImpl.getPersistenceUnitInfo(),nonNullProperties);
        }
      }
      if (undeployed) {
        return createContainerEntityManagerFactory(info,properties);
      }
    }
    if (transformer != null) {
      info.addTransformer(transformer);
    }
  }
  EntityManagerFactoryImpl factory=null;
  try {
    factory=new EntityManagerFactoryImpl(emSetupImpl,nonNullProperties);
    emSetupImpl.setRequiresConnection(requiresConnection);
    emSetupImpl.preInitializeCanonicalMetamodel(factory);
    if (emSetupImpl.shouldGetSessionOnCreateFactory(nonNullProperties)) {
      factory.getDatabaseSession();
    }
    return factory;
  }
 catch (  RuntimeException ex) {
    if (factory != null) {
      factory.close();
    }
 else {
      emSetupImpl.undeploy();
    }
    throw ex;
  }
}