Program: 31653
Project: 31653
Buggy source:
/** 
 * Determines whether or not a two way mapping is required for the relationship. Relationships annotated with either   {@link Relationship} direction INCOMING or OUTGOING and defined between two entities of the same typewill be considered for a dual mapping. Specifically, if the source and target entity are of the same type, and the related object from the source for relationship type R in direction D is the same as the related object from the target for relationship type R in direction D, then the relationship is mapped both ways.
 * @param srcObject the domain object representing the start node of the relationship
 * @param relationshipType the type of the relationship from the srcObject
 * @param tgtObject the domain object representing the end node of the relationship
 * @param relationshipDirection the direction of the relationship from the srcObject
 * @return true if the relationship should be mapped both ways, false otherwise
 */
private boolean bothWayMappingRequired(Object srcObject,String relationshipType,Object tgtObject,String relationshipDirection){
  boolean mapBothWays=false;
  if (tgtObject.getClass().equals(srcObject.getClass())) {
    ClassInfo tgtInfo=metaData.classInfo(tgtObject);
    for (    RelationalReader tgtRelReader : entityAccessStrategy.getRelationalReaders(tgtInfo)) {
      String tgtRelationshipDirection=tgtRelReader.relationshipDirection();
      if ((tgtRelationshipDirection.equals(Relationship.OUTGOING) || tgtRelationshipDirection.equals(Relationship.INCOMING)) && tgtRelReader.relationshipType().equals(relationshipType)) {
        if (relationshipDirection.equals(tgtRelationshipDirection)) {
          Object target=tgtRelReader.read(tgtObject);
          if (target != null) {
            if (target instanceof Iterable) {
              for (              Object relatedObject : (Iterable<?>)target) {
                if (relatedObject.equals(srcObject)) {
                  mapBothWays=true;
                }
              }
            }
 else             if (target.getClass().isArray()) {
              for (              Object relatedObject : (Object[])target) {
                if (relatedObject.equals(srcObject)) {
                  mapBothWays=true;
                }
              }
            }
 else {
              if (target.equals(srcObject)) {
                mapBothWays=true;
              }
            }
          }
        }
      }
    }
  }
  return mapBothWays;
}

Fixed version (ground truth):
/** 
 * Determines whether or not a two way mapping is required for the relationship. Relationships annotated with either   {@link Relationship} direction INCOMING or OUTGOING and defined between two entities of the same typewill be considered for a dual mapping. Specifically, if the source and target entity are of the same type, and the related object from the source for relationship type R in direction D is the same as the related object from the target for relationship type R in direction D, then the relationship is mapped both ways.
 * @param srcObject the domain object representing the start node of the relationship
 * @param relationshipType the type of the relationship from the srcObject
 * @param tgtObject the domain object representing the end node of the relationship
 * @param relationshipDirection the direction of the relationship from the srcObject
 * @return true if the relationship should be mapped both ways, false otherwise
 */
private boolean bothWayMappingRequired(Object srcObject,String relationshipType,Object tgtObject,String relationshipDirection){
  boolean mapBothWays=false;
  ClassInfo tgtInfo=metaData.classInfo(tgtObject);
  for (  RelationalReader tgtRelReader : entityAccessStrategy.getRelationalReaders(tgtInfo)) {
    String tgtRelationshipDirection=tgtRelReader.relationshipDirection();
    if ((tgtRelationshipDirection.equals(Relationship.OUTGOING) || tgtRelationshipDirection.equals(Relationship.INCOMING)) && tgtRelReader.relationshipType().equals(relationshipType)) {
      if (relationshipDirection.equals(tgtRelationshipDirection)) {
        Object target=tgtRelReader.read(tgtObject);
        if (target != null) {
          if (target instanceof Iterable) {
            for (            Object relatedObject : (Iterable<?>)target) {
              if (relatedObject.equals(srcObject)) {
                mapBothWays=true;
              }
            }
          }
 else           if (target.getClass().isArray()) {
            for (            Object relatedObject : (Object[])target) {
              if (relatedObject.equals(srcObject)) {
                mapBothWays=true;
              }
            }
          }
 else {
            if (target.equals(srcObject)) {
              mapBothWays=true;
            }
          }
        }
      }
    }
  }
  return mapBothWays;
}