Program: 176727
Project: 176727
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);
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,entity,initialNodeState,persistenceCache,id);
  }
 else {
    node=nodeInPersistenceCache;
    if (!DeepEquals.deepEquals(node.getData(),entity)) {
      node.setData(entity);
      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       if (Map.class.isAssignableFrom(childObject.getClass())) {
        Map childrenObjects=(Map)childObject;
        if (childrenObjects != null && !(childrenObjects instanceof PersistentCollection)) {
          for (          Map.Entry entry : (Set<Map.Entry>)childrenObjects.entrySet()) {
            addChildNodesToGraph(graph,node,relation,entry,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);
  if (nodeInPersistenceCache == null) {
    node=new Node(nodeId,entity,initialNodeState,persistenceCache,id);
  }
 else {
    node=nodeInPersistenceCache;
    if (!DeepEquals.deepEquals(node.getData(),entity)) {
      node.setData(entity);
      node.setDirty(true);
    }
 else     if (node.isProcessed()) {
      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       if (Map.class.isAssignableFrom(childObject.getClass())) {
        Map childrenObjects=(Map)childObject;
        if (childrenObjects != null && !(childrenObjects instanceof PersistentCollection)) {
          for (          Map.Entry entry : (Set<Map.Entry>)childrenObjects.entrySet()) {
            addChildNodesToGraph(graph,node,relation,entry,initialNodeState);
          }
        }
      }
 else {
        addChildNodesToGraph(graph,node,relation,childObject,initialNodeState);
      }
    }
  }
  node.setGraphCompleted(true);
  return node;
}