Program: 68678
Project: 68678
Buggy source:
/** 
 * Deploy a persistence session and return an EntityManagerFactory. Deployment takes a session that was partially created in the predeploy call and makes it whole. This means doing any configuration that requires the real class definitions for the entities.  In the predeploy phase we were in a stage where we were not let allowed to load the real classes. Deploy could be called several times - but only the first call does the actual deploying - additional calls allow to update session properties (in case the session is not connected). Note that there is no need to synchronize deploy method - it doesn't alter factoryCount and while deploy is executed no other method can alter the current state (predeploy call would just increment factoryCount; undeploy call would not drop factoryCount to 0). However precautions should be taken to handle concurrent calls to deploy, because those may alter the current state or connect the session.
 * @param realClassLoader The class loader that was used to load the entity classes. This loaderwill be maintained for the lifespan of the loaded classes.
 * @param additionalProperties added to predeployProperties for updateServerSession overriding existing properties.In JSE case it allows to alter properties in main (as opposed to preMain where preDeploy is called).
 * @return An EntityManagerFactory to be used by the Container to obtain EntityManagers
 */
public ServerSession deploy(ClassLoader realClassLoader,Map additionalProperties){
  if (state != STATE_PREDEPLOYED && state != STATE_DEPLOYED) {
    throw new PersistenceException(EntityManagerSetupException.cannotDeployWithoutPredeploy(persistenceUnitInfo.getPersistenceUnitName(),state));
  }
  session.log(SessionLog.FINEST,SessionLog.PROPERTIES,"String_Node_Str",new Object[]{getPersistenceUnitInfo().getPersistenceUnitName(),state,factoryCount});
  List<StructConverter> structConverters=null;
  try {
    Map deployProperties=mergeMaps(additionalProperties,predeployProperties);
    translateOldProperties(deployProperties,session);
    if (state == STATE_PREDEPLOYED) {
synchronized (session) {
        if (state == STATE_PREDEPLOYED) {
          try {
            session.getProject().convertClassNamesToClasses(realClassLoader);
            if (!isSessionLoadedFromSessionsXML) {
              processor.setClassLoader(realClassLoader);
              processor.addEntityListeners();
              processor.addNamedQueries();
              processor.processCustomizers();
              structConverters=processor.getStructConverters();
              processor=null;
            }
            initServerSession(deployProperties);
            if (session.getIntegrityChecker().hasErrors()) {
              session.handleException(new IntegrityException(session.getIntegrityChecker()));
            }
            session.getDatasourcePlatform().getConversionManager().setLoader(realClassLoader);
            state=STATE_DEPLOYED;
          }
 catch (          RuntimeException ex) {
            state=STATE_DEPLOY_FAILED;
            throw new PersistenceException(EntityManagerSetupException.deployFailed(persistenceUnitInfo.getPersistenceUnitName(),ex));
          }
        }
      }
    }
    if (!session.isConnected()) {
synchronized (session) {
        if (!session.isConnected()) {
          session.setProperties(deployProperties);
          updateServerSession(deployProperties,realClassLoader);
          if (isValidationOnly(deployProperties,false)) {
            session.initializeDescriptors();
          }
 else {
            if (isSessionLoadedFromSessionsXML) {
              if (!session.isConnected()) {
                session.login();
              }
            }
 else {
              login(session,deployProperties);
            }
            if (!isSessionLoadedFromSessionsXML) {
              addStructConverters(session,structConverters);
            }
            generateDDLFiles(session,deployProperties,!isInContainerMode);
          }
        }
      }
      List queries=session.getEjbqlPlaceHolderQueries();
      for (Iterator iterator=queries.iterator(); iterator.hasNext(); ) {
        EJBQLPlaceHolderQuery existingQuery=(EJBQLPlaceHolderQuery)iterator.next();
        DatabaseQuery databaseQuery=existingQuery.processEjbQLQuery(session);
        session.addQuery(databaseQuery.getName(),databaseQuery);
      }
      queries.clear();
    }
    return session;
  }
 catch (  IllegalArgumentException illegalArgumentException) {
    throw new javax.persistence.PersistenceException(illegalArgumentException);
  }
catch (  org.eclipse.persistence.exceptions.ValidationException exception) {
    throw new javax.persistence.PersistenceException(exception);
  }
 finally {
    session.log(SessionLog.FINEST,SessionLog.PROPERTIES,"String_Node_Str",new Object[]{getPersistenceUnitInfo().getPersistenceUnitName(),state,factoryCount});
  }
}

Fixed version (ground truth):
/** 
 * Deploy a persistence session and return an EntityManagerFactory. Deployment takes a session that was partially created in the predeploy call and makes it whole. This means doing any configuration that requires the real class definitions for the entities.  In the predeploy phase we were in a stage where we were not let allowed to load the real classes. Deploy could be called several times - but only the first call does the actual deploying - additional calls allow to update session properties (in case the session is not connected). Note that there is no need to synchronize deploy method - it doesn't alter factoryCount and while deploy is executed no other method can alter the current state (predeploy call would just increment factoryCount; undeploy call would not drop factoryCount to 0). However precautions should be taken to handle concurrent calls to deploy, because those may alter the current state or connect the session.
 * @param realClassLoader The class loader that was used to load the entity classes. This loaderwill be maintained for the lifespan of the loaded classes.
 * @param additionalProperties added to predeployProperties for updateServerSession overriding existing properties.In JSE case it allows to alter properties in main (as opposed to preMain where preDeploy is called).
 * @return An EntityManagerFactory to be used by the Container to obtain EntityManagers
 */
public ServerSession deploy(ClassLoader realClassLoader,Map additionalProperties){
  if (state != STATE_PREDEPLOYED && state != STATE_DEPLOYED) {
    throw new PersistenceException(EntityManagerSetupException.cannotDeployWithoutPredeploy(persistenceUnitInfo.getPersistenceUnitName(),state));
  }
  session.log(SessionLog.FINEST,SessionLog.PROPERTIES,"String_Node_Str",new Object[]{getPersistenceUnitInfo().getPersistenceUnitName(),state,factoryCount});
  List<StructConverter> structConverters=null;
  try {
    Map deployProperties=mergeMaps(additionalProperties,predeployProperties);
    translateOldProperties(deployProperties,session);
    if (state == STATE_PREDEPLOYED) {
synchronized (session) {
        if (state == STATE_PREDEPLOYED) {
          try {
            session.getProject().convertClassNamesToClasses(realClassLoader);
            if (!isSessionLoadedFromSessionsXML) {
              processor.setClassLoader(realClassLoader);
              processor.addEntityListeners();
              processor.addNamedQueries();
              processor.processCustomizers();
              structConverters=processor.getStructConverters();
              processor=null;
            }
            initServerSession(deployProperties);
            if (session.getIntegrityChecker().hasErrors()) {
              session.handleException(new IntegrityException(session.getIntegrityChecker()));
            }
            session.getDatasourcePlatform().getConversionManager().setLoader(realClassLoader);
            state=STATE_DEPLOYED;
          }
 catch (          RuntimeException ex) {
            state=STATE_DEPLOY_FAILED;
            throw new PersistenceException(EntityManagerSetupException.deployFailed(persistenceUnitInfo.getPersistenceUnitName(),ex));
          }
        }
      }
    }
    if (!session.isConnected()) {
synchronized (session) {
        if (!session.isConnected()) {
          session.setProperties(deployProperties);
          updateServerSession(deployProperties,realClassLoader);
          if (isValidationOnly(deployProperties,false)) {
            session.initializeDescriptors();
          }
 else {
            if (isSessionLoadedFromSessionsXML) {
              if (!session.isConnected()) {
                session.login();
              }
            }
 else {
              login(session,deployProperties);
            }
            if (!isSessionLoadedFromSessionsXML) {
              addStructConverters(session,structConverters);
            }
            generateDDL(session,deployProperties);
          }
        }
      }
      List queries=session.getEjbqlPlaceHolderQueries();
      for (Iterator iterator=queries.iterator(); iterator.hasNext(); ) {
        EJBQLPlaceHolderQuery existingQuery=(EJBQLPlaceHolderQuery)iterator.next();
        DatabaseQuery databaseQuery=existingQuery.processEjbQLQuery(session);
        session.addQuery(databaseQuery.getName(),databaseQuery);
      }
      queries.clear();
    }
    return session;
  }
 catch (  IllegalArgumentException illegalArgumentException) {
    throw new javax.persistence.PersistenceException(illegalArgumentException);
  }
catch (  org.eclipse.persistence.exceptions.ValidationException exception) {
    throw new javax.persistence.PersistenceException(exception);
  }
 finally {
    session.log(SessionLog.FINEST,SessionLog.PROPERTIES,"String_Node_Str",new Object[]{getPersistenceUnitInfo().getPersistenceUnitName(),state,factoryCount});
  }
}