Program: 177024
Project: 177024
Buggy source:
/** 
 * Compute graph.
 * @param e the e
 * @param graphs the graphs
 * @return the object
 * @throws Exception the exception
 */
public Object computeGraph(EnhanceEntity e,List<EntitySaveGraph> graphs,Map<Object,Object> collectionHolder,Client client,EntityMetadata m,PersistenceDelegator persistenceDelegeator) throws Exception {
  Client childClient=null;
  Class<?> childClazz=null;
  EntityMetadata childMetadata=null;
  for (  EntitySaveGraph g : graphs) {
    Relation relation=m.getRelation(g.getProperty().getName());
    if (relation.isRelatedViaJoinTable()) {
      computeJoinTableRelations(e,client,m,g,persistenceDelegeator,relation);
    }
 else {
      if (e.getEntity().getClass().equals(g.getChildClass())) {
        String relationName=g.getfKeyName();
        Object relationalValue=e.getRelations().get(relationName);
        childClazz=g.getParentClass();
        Field f=g.getProperty();
        if (!collectionHolder.containsKey(relationalValue)) {
          childMetadata=persistenceDelegeator.getMetadata(childClazz);
          childClient=persistenceDelegeator.getClient(childMetadata);
          Object child=childClient.find(childClazz,childMetadata,relationalValue.toString(),null);
          collectionHolder.put(relationalValue,child);
        }
        onBiDirection(e,client,g,m,collectionHolder.get(relationalValue),childMetadata,childClient);
        List<Object> collection=new ArrayList<Object>(1);
        collection.add(collectionHolder.get(relationalValue));
        PropertyAccessorHelper.set(e.getEntity(),f,PropertyAccessorHelper.isCollection(f.getType()) ? getFieldInstance(collection,f) : collection.get(0));
      }
 else {
        childClazz=g.getChildClass();
        childMetadata=persistenceDelegeator.getMetadata(childClazz);
        childClient=persistenceDelegeator.getClient(childMetadata);
        String relationName=g.getfKeyName();
        String relationalValue=e.getEntityId();
        Field f=g.getProperty();
        if (!collectionHolder.containsKey(relationalValue)) {
          List<Object> childs=null;
          if (MetadataUtils.useSecondryIndex(childMetadata.getPersistenceUnit())) {
            childs=childClient.find(relationName,relationalValue,childMetadata);
          }
 else {
            if (g.isSharedPrimaryKey()) {
              childs=new ArrayList();
              childs.add(childClient.find(childClazz,childMetadata,e.getEntityId(),null));
            }
 else {
              String query=getQuery(DocumentIndexer.PARENT_ID_CLASS,e.getEntity().getClass().getCanonicalName().toLowerCase(),DocumentIndexer.PARENT_ID_FIELD,e.getEntityId());
              Map<String,String> results=childClient.getIndexManager().search(query);
              Set<String> rsSet=new HashSet<String>(results.values());
              childs=(List<Object>)childClient.find(childClazz,rsSet.toArray(new String[]{}));
            }
          }
          collectionHolder.put(relationalValue,childs);
          if (childs != null) {
            for (            Object child : childs) {
              onBiDirection(e,client,g,m,child,childMetadata,childClient);
            }
          }
        }
        onReflect(e.getEntity(),f,(List)collectionHolder.get(relationalValue));
      }
    }
  }
  return e.getEntity();
}

Fixed version (ground truth):
/** 
 * Compute graph.
 * @param e the e
 * @param graphs the graphs
 * @return the object
 * @throws Exception the exception
 */
public Object computeGraph(EnhanceEntity e,List<EntitySaveGraph> graphs,Map<Object,Object> collectionHolder,Client client,EntityMetadata m,PersistenceDelegator persistenceDelegeator) throws Exception {
  Client childClient=null;
  Class<?> childClazz=null;
  EntityMetadata childMetadata=null;
  for (  EntitySaveGraph g : graphs) {
    Relation relation=m.getRelation(g.getProperty().getName());
    if (relation.isRelatedViaJoinTable()) {
      computeJoinTableRelations(e,client,m,g,persistenceDelegeator,relation);
    }
 else {
      if (e.getEntity().getClass().equals(g.getChildClass())) {
        String relationName=g.getfKeyName();
        Object relationalValue=e.getRelations().get(relationName);
        childClazz=g.getParentClass();
        childMetadata=persistenceDelegeator.getMetadata(childClazz);
        Field f=g.getProperty();
        if (!collectionHolder.containsKey(relationalValue)) {
          childClient=persistenceDelegeator.getClient(childMetadata);
          Object child=persistenceDelegeator.find(childClazz,relationalValue.toString());
          collectionHolder.put(relationalValue,child);
        }
        onBiDirection(e,client,g,m,collectionHolder.get(relationalValue),childMetadata,childClient);
        List<Object> collection=new ArrayList<Object>(1);
        collection.add(collectionHolder.get(relationalValue));
        PropertyAccessorHelper.set(e.getEntity(),f,PropertyAccessorHelper.isCollection(f.getType()) ? getFieldInstance(collection,f) : collection.get(0));
      }
 else {
        childClazz=g.getChildClass();
        childMetadata=persistenceDelegeator.getMetadata(childClazz);
        childClient=persistenceDelegeator.getClient(childMetadata);
        String relationName=g.getfKeyName();
        String relationalValue=e.getEntityId();
        Field f=g.getProperty();
        if (!collectionHolder.containsKey(relationalValue)) {
          List<Object> childs=null;
          if (MetadataUtils.useSecondryIndex(childMetadata.getPersistenceUnit())) {
            childs=childClient.find(relationName,relationalValue,childMetadata);
          }
 else {
            if (g.isSharedPrimaryKey()) {
              childs=new ArrayList();
              childs.add(persistenceDelegeator.find(childClazz,relationalValue.toString()));
            }
 else {
              String query=getQuery(DocumentIndexer.PARENT_ID_CLASS,e.getEntity().getClass().getCanonicalName().toLowerCase(),DocumentIndexer.PARENT_ID_FIELD,e.getEntityId());
              Map<String,String> results=childClient.getIndexManager().search(query);
              Set<String> rsSet=new HashSet<String>(results.values());
              childs=(List<Object>)persistenceDelegeator.find(childClazz,rsSet.toArray(new String[]{}));
            }
          }
          collectionHolder.put(relationalValue,childs);
          if (childs != null) {
            for (            Object child : childs) {
              onBiDirection(e,client,g,m,child,childMetadata,childClient);
            }
          }
        }
        onReflect(e.getEntity(),f,(List)collectionHolder.get(relationalValue));
      }
    }
  }
  return e.getEntity();
}