Program: 176998
Project: 176998
Buggy source:
/** 
 * On bi direction.
 * @param entity the entity
 * @param objectGraph the object graph
 * @param client the client
 * @param rowId the row id
 * @param entityClass the entity class
 * @param chids the chids
 * @param childMetadata the child metadata
 * @param childClient the child client
 * @throws Exception the exception
 */
private void onBiDirection(EnhanceEntity e,Client client,EntitySaveGraph objectGraph,EntityMetadata origMetadata,Object child,EntityMetadata childMetadata,Client childClient) throws Exception {
  if (!objectGraph.isUniDirectional()) {
    List obj=new ArrayList();
    Relation relation=childMetadata.getRelation(objectGraph.getBidirectionalProperty().getName());
    if (relation.getType().equals(ForeignKey.ONE_TO_MANY) || relation.getType().equals(ForeignKey.MANY_TO_MANY)) {
      String query=null;
      try {
        String id=PropertyAccessorHelper.getId(child,childMetadata);
        List<Object> results=null;
        if (MetadataUtils.useSecondryIndex(client.getPersistenceUnit())) {
          results=client.find(objectGraph.getfKeyName(),id,origMetadata);
        }
 else {
          Map<String,String> keys=null;
          if (relation.getType().equals(ForeignKey.ONE_TO_MANY)) {
            query=getQuery(DocumentIndexer.PARENT_ID_CLASS,child.getClass().getCanonicalName().toLowerCase(),DocumentIndexer.PARENT_ID_FIELD,id);
            keys=client.getIndexManager().search(query);
          }
 else {
            query=getQuery(DocumentIndexer.ENTITY_CLASS_FIELD,child.getClass().getCanonicalName().toLowerCase(),DocumentIndexer.ENTITY_ID_FIELD,id);
            keys=client.getIndexManager().fetchRelation(query);
          }
          Set<String> uqSet=new HashSet<String>(keys.values());
          results=new ArrayList<Object>();
          for (          String rowKey : uqSet) {
            results.add(client.find(e.getEntity().getClass(),origMetadata,rowKey,null));
          }
        }
        if (results != null) {
          obj.addAll(results);
        }
      }
 catch (      PropertyAccessException ex) {
        log.error("String_Node_Str" + ex.getMessage());
        throw new QueryHandlerException(ex.getMessage());
      }
      for (      Object o : obj) {
        Field f=objectGraph.getProperty();
        if (PropertyAccessorHelper.isCollection(f.getType())) {
          List l=new ArrayList();
          l.add(child);
          Object oo=getFieldInstance(l,f);
          PropertyAccessorHelper.set(o,f,oo);
        }
 else {
          PropertyAccessorHelper.set(o,f,child);
        }
      }
    }
 else {
      obj.add(e.getEntity());
    }
    try {
      PropertyAccessorHelper.set(child,objectGraph.getBidirectionalProperty(),PropertyAccessorHelper.isCollection(objectGraph.getBidirectionalProperty().getType()) ? getFieldInstance(obj,objectGraph.getBidirectionalProperty()) : e.getEntity());
    }
 catch (    PropertyAccessException ex) {
      log.error("String_Node_Str" + ex.getMessage());
      throw new QueryHandlerException(ex.getMessage());
    }
  }
}

Fixed version (ground truth):
/** 
 * On bi direction.
 * @param entity the entity
 * @param objectGraph the object graph
 * @param client the client
 * @param rowId the row id
 * @param entityClass the entity class
 * @param chids the chids
 * @param childMetadata the child metadata
 * @param childClient the child client
 * @throws Exception the exception
 */
private void onBiDirection(EnhanceEntity e,Client client,EntitySaveGraph objectGraph,EntityMetadata origMetadata,Object child,EntityMetadata childMetadata,Client childClient) throws Exception {
  if (!objectGraph.isUniDirectional() && child != null) {
    List obj=new ArrayList();
    Relation relation=childMetadata.getRelation(objectGraph.getBidirectionalProperty().getName());
    if (relation.getType().equals(ForeignKey.ONE_TO_MANY) || relation.getType().equals(ForeignKey.MANY_TO_MANY)) {
      String query=null;
      try {
        String id=PropertyAccessorHelper.getId(child,childMetadata);
        List<Object> results=null;
        if (MetadataUtils.useSecondryIndex(client.getPersistenceUnit())) {
          results=client.find(objectGraph.getfKeyName(),id,origMetadata);
        }
 else {
          Map<String,String> keys=null;
          if (relation.getType().equals(ForeignKey.ONE_TO_MANY)) {
            query=getQuery(DocumentIndexer.PARENT_ID_CLASS,child.getClass().getCanonicalName().toLowerCase(),DocumentIndexer.PARENT_ID_FIELD,id,e.getEntity().getClass().getCanonicalName().toLowerCase());
            keys=client.getIndexManager().search(query);
          }
 else {
            query=getQuery(DocumentIndexer.ENTITY_CLASS_FIELD,child.getClass().getCanonicalName().toLowerCase(),DocumentIndexer.ENTITY_ID_FIELD,id,null);
            keys=client.getIndexManager().fetchRelation(query);
          }
          Set<String> uqSet=new HashSet<String>(keys.values());
          results=new ArrayList<Object>();
          for (          String rowKey : uqSet) {
            results.add(client.find(e.getEntity().getClass(),origMetadata,rowKey,null));
          }
        }
        if (results != null) {
          obj.addAll(results);
        }
      }
 catch (      PropertyAccessException ex) {
        log.error("String_Node_Str" + ex.getMessage());
        throw new QueryHandlerException(ex.getMessage());
      }
      for (      Object o : obj) {
        Field f=objectGraph.getProperty();
        if (PropertyAccessorHelper.isCollection(f.getType())) {
          List l=new ArrayList();
          l.add(child);
          Object oo=getFieldInstance(l,f);
          PropertyAccessorHelper.set(o,f,oo);
        }
 else {
          PropertyAccessorHelper.set(o,f,child);
        }
      }
    }
 else {
      obj.add(e.getEntity());
    }
    try {
      PropertyAccessorHelper.set(child,objectGraph.getBidirectionalProperty(),PropertyAccessorHelper.isCollection(objectGraph.getBidirectionalProperty().getType()) ? getFieldInstance(obj,objectGraph.getBidirectionalProperty()) : e.getEntity());
    }
 catch (    PropertyAccessException ex) {
      log.error("String_Node_Str" + ex.getMessage());
      throw new QueryHandlerException(ex.getMessage());
    }
  }
}