Program: 176915
Project: 176915
Buggy source:
/** 
 * Constructs and returns   {@link Node} representation for a given entity object.Output is fully constructed graph with relationships embedded. Each node is put into <code>graph</code> once it is constructed.
 * @param entity
 * @return
 */
private Node getNode(Object entity,ObjectGraph graph,NodeState initialNodeState){
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
  if (entityMetadata == null) {
    return null;
  }
  Object id=PropertyAccessorHelper.getId(entity,entityMetadata);
  String nodeId=getNodeId(id,entity);
  Node node=graph.getNode(nodeId);
  if (node != null) {
    return node;
  }
  Node nodeInPersistenceCache=persistenceCache.getMainCache().getNodeFromCache(nodeId);
  Object nodeDataCopy=ObjectUtils.deepCopy(entity);
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,nodeDataCopy,initialNodeState,persistenceCache);
  }
 else {
    node=nodeInPersistenceCache;
    if (!DeepEquals.deepEquals(node.getData(),entity)) {
      node.setData(nodeDataCopy);
      node.setDirty(true);
    }
 else {
      node.setDirty(false);
    }
  }
  graph.addNode(nodeId,node);
  for (  Relation relation : entityMetadata.getRelations()) {
    Object childObject=PropertyAccessorHelper.getObject(entity,relation.getProperty());
    if (childObject != null) {
      if (Collection.class.isAssignableFrom(childObject.getClass())) {
        Collection childrenObjects=(Collection)childObject;
        for (        Object childObj : childrenObjects) {
          if (childObj != null) {
            addChildNodesToGraph(graph,node,relation,childObj,initialNodeState);
          }
        }
      }
 else {
        addChildNodesToGraph(graph,node,relation,childObject,initialNodeState);
      }
    }
  }
  return node;
}

Fixed version (ground truth):
/** 
 * Constructs and returns   {@link Node} representation for a given entity object.Output is fully constructed graph with relationships embedded. Each node is put into <code>graph</code> once it is constructed.
 * @param entity
 * @return
 */
private Node getNode(Object entity,ObjectGraph graph,NodeState initialNodeState){
  EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entity.getClass());
  if (entityMetadata == null) {
    return null;
  }
  Object id=PropertyAccessorHelper.getId(entity,entityMetadata);
  String nodeId=getNodeId(id,entity);
  if (graph.getNode(nodeId) != null) {
    return null;
  }
  Node node=null;
  Node nodeInPersistenceCache=persistenceCache.getMainCache().getNodeFromCache(nodeId);
  Object nodeDataCopy=ObjectUtils.deepCopy(entity);
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,nodeDataCopy,initialNodeState,persistenceCache);
  }
 else {
    node=nodeInPersistenceCache;
    if (!DeepEquals.deepEquals(node.getData(),entity)) {
      node.setData(nodeDataCopy);
      node.setDirty(true);
    }
 else {
      node.setDirty(false);
    }
  }
  graph.addNode(nodeId,node);
  for (  Relation relation : entityMetadata.getRelations()) {
    Object childObject=PropertyAccessorHelper.getObject(entity,relation.getProperty());
    if (childObject != null) {
      if (Collection.class.isAssignableFrom(childObject.getClass())) {
        Collection childrenObjects=(Collection)childObject;
        for (        Object childObj : childrenObjects) {
          if (childObj != null) {
            addChildNodesToGraph(graph,node,relation,childObj,initialNodeState);
          }
        }
      }
 else {
        addChildNodesToGraph(graph,node,relation,childObject,initialNodeState);
      }
    }
  }
  return node;
}