Program: 176294
Project: 176294
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) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (initialNodeState != null && initialNodeState.getClass().equals(TransientState.class)) {
    Object id=PropertyAccessorHelper.getId(entity,entityMetadata);
    Node nodeInPersistenceCache=null;
    if (id != null) {
      String nodeId=ObjectGraphUtils.getNodeId(id,entity.getClass());
      nodeInPersistenceCache=persistenceCache.getMainCache().getNodeFromCache(nodeId);
    }
    if (nodeInPersistenceCache == null) {
      idGenerator.generateAndSetId(entity,entityMetadata,pd);
    }
  }
  if (!validator.isValidEntityObject(entity)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Object id=PropertyAccessorHelper.getId(entity,entityMetadata);
  String nodeId=ObjectGraphUtils.getNodeId(id,entity.getClass());
  Node node=graph.getNode(nodeId);
  if (node != null) {
    if (node.isGraphCompleted()) {
      return node;
    }
    return 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 && !ProxyHelper.isProxy(childObject)) {
      EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(childObject.getClass());
      if (metadata != null && relation.isJoinedByPrimaryKey()) {
        PropertyAccessorHelper.setId(childObject,metadata,PropertyAccessorHelper.getId(entity,entityMetadata));
      }
      if (Collection.class.isAssignableFrom(childObject.getClass())) {
        Collection childrenObjects=(Collection)childObject;
        if (childrenObjects != null && !ProxyHelper.isProxyCollection(childrenObjects))         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 && !ProxyHelper.isProxyCollection(childrenObjects)) {
          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) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (((Field)entityMetadata.getIdAttribute().getJavaMember()).isAnnotationPresent(GeneratedValue.class)) {
    Object id=PropertyAccessorHelper.getId(entity,entityMetadata);
    Node nodeInPersistenceCache=null;
    if (id != null) {
      String nodeId=ObjectGraphUtils.getNodeId(id,entity.getClass());
      nodeInPersistenceCache=persistenceCache.getMainCache().getNodeFromCache(nodeId);
    }
    if (nodeInPersistenceCache == null || !nodeInPersistenceCache.getCurrentNodeState().equals(ManagedState.class)) {
      idGenerator.generateAndSetId(entity,entityMetadata,pd);
    }
  }
  if (!validator.isValidEntityObject(entity)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Object id=PropertyAccessorHelper.getId(entity,entityMetadata);
  String nodeId=ObjectGraphUtils.getNodeId(id,entity.getClass());
  Node node=graph.getNode(nodeId);
  if (node != null) {
    if (node.isGraphCompleted()) {
      return node;
    }
    return 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 && !ProxyHelper.isProxy(childObject)) {
      EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(childObject.getClass());
      if (metadata != null && relation.isJoinedByPrimaryKey()) {
        PropertyAccessorHelper.setId(childObject,metadata,PropertyAccessorHelper.getId(entity,entityMetadata));
      }
      if (Collection.class.isAssignableFrom(childObject.getClass())) {
        Collection childrenObjects=(Collection)childObject;
        if (childrenObjects != null && !ProxyHelper.isProxyCollection(childrenObjects))         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 && !ProxyHelper.isProxyCollection(childrenObjects)) {
          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;
}