Program: 64628
Project: 64628
Buggy source:
/** 
 * Answer the ClassLoader to use to create an EntityManager.  The result is a CompositeClassLoader capable of loading  classes from the optionally provided ClassLoader, the  bundle that provides the persistence unit (i.e., contains the persistence.xml, and EclipseLink classes (since the  persistence unit bundle may not have an explicit dependency on EclipseLink).
 * @param persistenceUnitName
 * @param properties
 * @return ClassLoader
 */
public ClassLoader getClassLoader(String persistenceUnitName,Map properties){
  ClassLoader previouslyDefinedLoader=puClassLoaders.get(persistenceUnitName);
  if (previouslyDefinedLoader != null) {
    return previouslyDefinedLoader;
  }
  List<ClassLoader> loaders=new ArrayList<ClassLoader>();
  ClassLoader propertyClassLoader=null;
  if (properties != null) {
    Object propertyValue=properties.get(PersistenceUnitProperties.CLASSLOADER);
    if ((propertyValue != null) && (propertyValue instanceof ClassLoader)) {
      propertyClassLoader=(ClassLoader)propertyValue;
      loaders.add(propertyClassLoader);
    }
  }
  Bundle bundle=puToBundle.get(persistenceUnitName);
  if (bundle != null) {
    ClassLoader bundleClassLoader=new BundleProxyClassLoader(bundle);
    loaders.add(bundleClassLoader);
  }
  if ((propertyClassLoader == null) && (bundle == null)) {
    throw EntityManagerSetupException.couldNotFindPersistenceUnitBundle(persistenceUnitName);
  }
  BundleContext context=Activator.getContext();
  if (context != null) {
    Bundle[] bundles=context.getBundles();
    Bundle coreBundle=null;
    for (int i=0; i < bundles.length; i++) {
      if (ORG_ECLIPSE_PERSISTENCE_CORE.equals(bundles[i].getSymbolicName())) {
        coreBundle=bundles[i];
        loaders.add(new BundleProxyClassLoader(coreBundle));
        break;
      }
    }
    ClassLoader eclipseLinkJpaClassLoader=new BundleProxyClassLoader(context.getBundle());
    loaders.add(eclipseLinkJpaClassLoader);
  }
  ClassLoader puClassLoader=null;
  if ((loaders.size() == 1) && (loaders.get(0) == propertyClassLoader)) {
    puClassLoader=propertyClassLoader;
  }
 else {
    puClassLoader=new CompositeClassLoader(loaders);
  }
  puClassLoaders.put(persistenceUnitName,puClassLoader);
  return puClassLoader;
}

Fixed version (ground truth):
/** 
 * Answer the ClassLoader to use to create an EntityManager.  The result is a CompositeClassLoader capable of loading  classes from the optionally provided ClassLoader, the  bundle that provides the persistence unit (i.e., contains the persistence.xml, and EclipseLink classes (since the  persistence unit bundle may not have an explicit dependency on EclipseLink).
 * @param persistenceUnitName
 * @param properties
 * @return ClassLoader
 */
public ClassLoader getClassLoader(String persistenceUnitName,Map properties){
  ClassLoader previouslyDefinedLoader=puClassLoaders.get(persistenceUnitName);
  if (previouslyDefinedLoader != null) {
    return previouslyDefinedLoader;
  }
  List<ClassLoader> loaders=new ArrayList<ClassLoader>();
  ClassLoader propertyClassLoader=null;
  if (properties != null) {
    Object propertyValue=properties.get(PersistenceUnitProperties.CLASSLOADER);
    if ((propertyValue != null) && (propertyValue instanceof ClassLoader)) {
      propertyClassLoader=(ClassLoader)propertyValue;
      loaders.add(propertyClassLoader);
    }
  }
  Bundle bundle=puToBundle.get(persistenceUnitName);
  if (bundle != null) {
    ClassLoader bundleClassLoader=new BundleProxyClassLoader(bundle);
    loaders.add(bundleClassLoader);
  }
  if ((propertyClassLoader == null) && (bundle == null)) {
    throw EntityManagerSetupException.couldNotFindPersistenceUnitBundle(persistenceUnitName);
  }
  BundleContext context=Activator.getContext();
  if (context != null) {
    Bundle[] bundles=context.getBundles();
    Bundle coreBundle=null;
    for (int i=0; i < bundles.length; i++) {
      if (ORG_ECLIPSE_PERSISTENCE_CORE.equals(bundles[i].getSymbolicName())) {
        coreBundle=bundles[i];
        loaders.add(new BundleProxyClassLoader(coreBundle));
        break;
      }
    }
    ClassLoader eclipseLinkJpaClassLoader=new BundleProxyClassLoader(context.getBundle());
    loaders.add(eclipseLinkJpaClassLoader);
  }
  ClassLoader puClassLoader=null;
  if ((loaders.size() == 1) && (loaders.get(0) == propertyClassLoader)) {
    puClassLoader=propertyClassLoader;
  }
 else {
    puClassLoader=new CompositeClassLoader(loaders);
    Object propertyValue=properties.get(PersistenceUnitProperties.CLASSLOADER);
    if ((propertyValue != null) && (propertyValue instanceof ClassLoader)) {
      properties.put(PersistenceUnitProperties.CLASSLOADER,propertyValue);
    }
  }
  puClassLoaders.put(persistenceUnitName,puClassLoader);
  return puClassLoader;
}