Program: 36068
Project: 36068
Buggy source:
/** 
 * This function makes sure that the two events in each TLink follow document order. If not, then we invert the order so event 1 is 2 and 2 is 1, and we also invert the ordering relation.
 * @param docs The documents to normalize.
 */
public static void normalizeAllTlinksByTextOrder(SieveDocuments docs){
  for (  SieveDocument doc : docs.getDocuments()) {
    List<TLink> removal=new ArrayList<TLink>();
    List<TLink> addition=new ArrayList<TLink>();
    for (    TLink link : doc.getTlinks()) {
      if (link instanceof EventEventLink) {
        TextEvent first=doc.getEventByEiid(link.getId1());
        TextEvent second=doc.getEventByEiid(link.getId2());
        if (first == null || second == null)         System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else         if (!first.isBeforeInText(second)) {
          removal.add(link);
          TLink.Type invertedRelation=TLink.invertRelation(link.getRelation());
          TLink newlink=new EventEventLink(link.getId2(),link.getId1(),invertedRelation);
          newlink.setRelationConfidence(link.getRelationConfidence());
          addition.add(newlink);
        }
      }
 else       if (link instanceof TimeTimeLink) {
        Timex first=doc.getTimexByTid(link.getId1());
        Timex second=doc.getTimexByTid(link.getId2());
        boolean flip=false;
        if (first == null || second == null)         System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else         if (first.getDocumentFunction() == Timex.DocumentFunction.CREATION_TIME && second.getDocumentFunction() != Timex.DocumentFunction.CREATION_TIME) {
          flip=true;
        }
 else         if (first.getDocumentFunction() != Timex.DocumentFunction.CREATION_TIME && second.getDocumentFunction() != Timex.DocumentFunction.CREATION_TIME && !first.isBeforeInText(second)) {
          flip=true;
        }
        if (flip) {
          removal.add(link);
          TLink.Type invertedRelation=TLink.invertRelation(link.getRelation());
          TLink newlink=new TimeTimeLink(link.getId2(),link.getId1(),invertedRelation);
          newlink.setRelationConfidence(link.getRelationConfidence());
          addition.add(newlink);
        }
      }
 else       if (link instanceof EventTimeLink) {
        TextEvent event;
        Timex time;
        boolean flip=false;
        if (link.getId1().startsWith("String_Node_Str")) {
          event=doc.getEventByEiid(link.getId1());
          time=doc.getTimexByTid(link.getId2());
          if (event == null || time == null)           System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else           if (!time.isDCT() && (time.getSid() < event.getSid() || (time.getSid() == event.getSid() && time.getTokenOffset() < event.getIndex())))           flip=true;
        }
 else {
          event=doc.getEventByEiid(link.getId2());
          time=doc.getTimexByTid(link.getId1());
          if (event == null || time == null)           System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else           if (time.isDCT())           flip=true;
 else           if (event.getSid() < time.getSid() || (event.getSid() == time.getSid() && event.getIndex() < time.getTokenOffset()))           flip=true;
        }
        if (flip) {
          removal.add(link);
          TLink.Type invertedRelation=TLink.invertRelation(link.getRelation());
          TLink newlink=new EventTimeLink(link.getId2(),link.getId1(),invertedRelation);
          newlink.setRelationConfidence(link.getRelationConfidence());
          addition.add(newlink);
        }
      }
 else {
        System.out.println("String_Node_Str");
      }
    }
    for (    TLink link : removal)     doc.removeTlink(link);
    for (    TLink link : addition)     doc.addTlink(link);
  }
}

Fixed version (ground truth):
/** 
 * This function makes sure that the two events in each TLink follow document order. If not, then we invert the order so event 1 is 2 and 2 is 1, and we also invert the ordering relation.
 * @param docs The documents to normalize.
 */
public static void normalizeAllTlinksByTextOrder(SieveDocuments docs){
  for (  SieveDocument doc : docs.getDocuments()) {
    List<TLink> removal=new ArrayList<TLink>();
    List<TLink> addition=new ArrayList<TLink>();
    for (    TLink link : doc.getTlinks()) {
      if (link instanceof EventEventLink) {
        TextEvent first=doc.getEventByEiid(link.getId1());
        TextEvent second=doc.getEventByEiid(link.getId2());
        if (first == null || second == null)         System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else         if (!first.isBeforeInText(second)) {
          removal.add(link);
          TLink.Type invertedRelation=TLink.invertRelation(link.getRelation());
          TLink newlink=TLink.clone(link);
          newlink.setId1(link.getId2());
          newlink.setId2(link.getId1());
          newlink.setRelation(invertedRelation);
          addition.add(newlink);
        }
      }
 else       if (link instanceof TimeTimeLink) {
        Timex first=doc.getTimexByTid(link.getId1());
        Timex second=doc.getTimexByTid(link.getId2());
        boolean flip=false;
        if (first == null || second == null)         System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else         if (first.getDocumentFunction() == Timex.DocumentFunction.CREATION_TIME && second.getDocumentFunction() != Timex.DocumentFunction.CREATION_TIME) {
          flip=true;
        }
 else         if (first.getDocumentFunction() != Timex.DocumentFunction.CREATION_TIME && second.getDocumentFunction() != Timex.DocumentFunction.CREATION_TIME && !first.isBeforeInText(second)) {
          flip=true;
        }
        if (flip) {
          removal.add(link);
          TLink.Type invertedRelation=TLink.invertRelation(link.getRelation());
          TLink newlink=TLink.clone(link);
          newlink.setId1(link.getId2());
          newlink.setId2(link.getId1());
          newlink.setRelation(invertedRelation);
          addition.add(newlink);
        }
      }
 else       if (link instanceof EventTimeLink) {
        TextEvent event;
        Timex time;
        boolean flip=false;
        if (link.getId1().startsWith("String_Node_Str")) {
          event=doc.getEventByEiid(link.getId1());
          time=doc.getTimexByTid(link.getId2());
          if (event == null || time == null)           System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else           if (!time.isDCT() && (time.getSid() < event.getSid() || (time.getSid() == event.getSid() && time.getTokenOffset() < event.getIndex())))           flip=true;
        }
 else {
          event=doc.getEventByEiid(link.getId2());
          time=doc.getTimexByTid(link.getId1());
          if (event == null || time == null)           System.out.println("String_Node_Str" + doc.getDocname() + "String_Node_Str"+ link);
 else           if (time.isDCT())           flip=true;
 else           if (event.getSid() < time.getSid() || (event.getSid() == time.getSid() && event.getIndex() < time.getTokenOffset()))           flip=true;
        }
        if (flip) {
          removal.add(link);
          TLink.Type invertedRelation=TLink.invertRelation(link.getRelation());
          TLink newlink=TLink.clone(link);
          newlink.setId1(link.getId2());
          newlink.setId2(link.getId1());
          newlink.setRelation(invertedRelation);
          addition.add(newlink);
        }
      }
 else {
        System.out.println("String_Node_Str");
      }
    }
    for (    TLink link : removal)     doc.removeTlink(link);
    for (    TLink link : addition)     doc.addTlink(link);
  }
}