Program: 176817
Project: 176817
Buggy source:
/** 
 * Constructs and returns   {@link Node} representation for a given entityobject. 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=ObjectGraphUtils.getNodeId(id,entity);
  Node node=graph.getNode(nodeId);
  if (node != null) {
    if (node.isGraphCompleted()) {
      return node;
    }
 else {
      return null;
    }
  }
  node=null;
  Node nodeInPersistenceCache=persistenceCache.getMainCache().getNodeFromCache(nodeId);
  Object nodeDataCopy=ObjectUtils.deepCopy(entity);
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,nodeDataCopy,initialNodeState,persistenceCache,id);
  }
 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);
      }
    }
  }
  node.setGraphCompleted(true);
  return node;
}

Fixed version (ground truth):
/** 
 * Constructs and returns   {@link Node} representation for a given entityobject. 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=ObjectGraphUtils.getNodeId(id,entity);
  Node node=graph.getNode(nodeId);
  if (node != null) {
    if (node.isGraphCompleted()) {
      return node;
    }
 else {
      return null;
    }
  }
  node=null;
  Node nodeInPersistenceCache=persistenceCache.getMainCache().getNodeFromCache(nodeId);
  Object nodeDataCopy=ObjectUtils.deepCopy(entity);
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,nodeDataCopy,initialNodeState,persistenceCache,id);
  }
 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;
        if (childrenObjects != null && !(childrenObjects instanceof PersistentCollection))         for (        Object childObj : childrenObjects) {
          if (childObj != null) {
            addChildNodesToGraph(graph,node,relation,childObj,initialNodeState);
          }
        }
      }
 else {
        addChildNodesToGraph(graph,node,relation,childObject,initialNodeState);
      }
    }
  }
  node.setGraphCompleted(true);
  return node;
}