Program: 176930
Project: 176930
Buggy source:
private void populateRelationFromJoinTable(EnhanceEntity e,Client client,EntityMetadata entityMetadata,PersistenceDelegator delegator,Relation relation){
  Object entity=e.getEntity();
  JoinTableMetadata jtMetadata=relation.getJoinTableMetadata();
  String joinTableName=jtMetadata.getJoinTableName();
  Set<String> joinColumns=jtMetadata.getJoinColumns();
  Set<String> inverseJoinColumns=jtMetadata.getInverseJoinColumns();
  String joinColumnName=(String)joinColumns.toArray()[0];
  String inverseJoinColumnName=(String)inverseJoinColumns.toArray()[0];
  EntityMetadata relMetadata=delegator.getMetadata(relation.getTargetEntity());
  Client pClient=delegator.getClient(entityMetadata);
  List<?> foreignKeys=pClient.getColumnsById(joinTableName,joinColumnName,inverseJoinColumnName,e.getEntityId());
  List childrenEntities=new ArrayList();
  for (  Object foreignKey : foreignKeys) {
    EntityMetadata childMetadata=delegator.getMetadata(relation.getTargetEntity());
    Client childClient=delegator.getClient(childMetadata);
    Object child=delegator.find(relation.getTargetEntity(),foreignKey);
    onBiDirection(delegator,e,pClient,relation,getBiDirectionalField(entity.getClass(),relation.getTargetEntity()),joinColumnName,entityMetadata,child,childMetadata,childClient);
    childrenEntities.add(child);
  }
  Field childField=relation.getProperty();
  try {
    PropertyAccessorHelper.set(entity,childField,PropertyAccessorHelper.isCollection(childField.getType()) ? getFieldInstance(childrenEntities,childField) : childrenEntities.get(0));
  }
 catch (  PropertyAccessException ex) {
    throw new EntityReaderException(ex);
  }
}

Fixed version (ground truth):
private void populateRelationFromJoinTable(EnhanceEntity e,Client client,EntityMetadata entityMetadata,PersistenceDelegator delegator,Relation relation){
  Object entity=e.getEntity();
  JoinTableMetadata jtMetadata=relation.getJoinTableMetadata();
  String joinTableName=jtMetadata.getJoinTableName();
  Set<String> joinColumns=jtMetadata.getJoinColumns();
  Set<String> inverseJoinColumns=jtMetadata.getInverseJoinColumns();
  String joinColumnName=(String)joinColumns.toArray()[0];
  String inverseJoinColumnName=(String)inverseJoinColumns.toArray()[0];
  EntityMetadata relMetadata=delegator.getMetadata(relation.getTargetEntity());
  Client pClient=delegator.getClient(entityMetadata);
  List<?> foreignKeys=pClient.getColumnsById(joinTableName,joinColumnName,inverseJoinColumnName,e.getEntityId());
  List childrenEntities=new ArrayList();
  for (  Object foreignKey : foreignKeys) {
    EntityMetadata childMetadata=delegator.getMetadata(relation.getTargetEntity());
    Client childClient=delegator.getClient(childMetadata);
    Object child=delegator.find(relation.getTargetEntity(),foreignKey);
    Object obj=child instanceof EnhanceEntity && child != null ? ((EnhanceEntity)child).getEntity() : child;
    onBiDirection(delegator,e,pClient,relation,getBiDirectionalField(entity.getClass(),relation.getTargetEntity()),joinColumnName,entityMetadata,obj,childMetadata,childClient);
    childrenEntities.add(obj);
  }
  Field childField=relation.getProperty();
  try {
    PropertyAccessorHelper.set(entity,childField,PropertyAccessorHelper.isCollection(childField.getType()) ? getFieldInstance(childrenEntities,childField) : childrenEntities.get(0));
  }
 catch (  PropertyAccessException ex) {
    throw new EntityReaderException(ex);
  }
}