Program: 117453
Project: 117453
Buggy source:
@Override public void onRecordAfterUpdate(ODocument doc){
  if (enter()) {
    try {
      OClass thisOClass=doc.getSchemaClass();
      if (thisOClass == null)       return;
      Collection<OProperty> refProperties=getCache().get(thisOClass);
      if (refProperties != null && refProperties.size() > 0) {
        String[] changedFields=doc.getDirtyFields();
        for (        String field : changedFields) {
          OProperty changedProperty=thisOClass.getProperty(field);
          if (refProperties.contains(changedProperty)) {
            OProperty inverseProperty=CustomAttributes.PROP_INVERSE.getValue(changedProperty);
            if (changedProperty.getType().isMultiValue()) {
              OMultiValueChangeTimeLine<Object,Object> timeline=doc.getCollectionTimeLine(field);
              List<OMultiValueChangeEvent<Object,Object>> events=timeline.getMultiValueChangeEvents();
              for (              OMultiValueChangeEvent<Object,Object> event : events) {
                OIdentifiable toAddTo=null;
                OIdentifiable toRemoveFrom=null;
switch (event.getChangeType()) {
case ADD:
                  toAddTo=(OIdentifiable)event.getValue();
                break;
case UPDATE:
              toAddTo=(OIdentifiable)event.getValue();
            toRemoveFrom=(OIdentifiable)event.getOldValue();
          break;
case REMOVE:
        toRemoveFrom=(OIdentifiable)event.getOldValue();
      break;
  }
  if (toAddTo != null)   addLink((ODocument)toAddTo.getRecord(),inverseProperty,doc);
  if (toRemoveFrom != null)   removeLink((ODocument)toRemoveFrom.getRecord(),inverseProperty,doc);
}
}
 else {
Object original=doc.getOriginalValue(field);
Object current=doc.field(field);
if (original != null && original instanceof OIdentifiable) removeLink((ODocument)((OIdentifiable)original).getRecord(),inverseProperty,doc);
if (current != null && current instanceof OIdentifiable) addLink((ODocument)((OIdentifiable)current).getRecord(),inverseProperty,doc);
}
}
}
}
}
 catch (ExecutionException e) {
LOG.error("String_Node_Str",e);
}
 finally {
exit();
}
}
}

Fixed version (ground truth):
@Override public void onRecordAfterUpdate(ODocument doc){
  if (enter()) {
    try {
      OClass thisOClass=doc.getSchemaClass();
      if (thisOClass == null)       return;
      Collection<OProperty> refProperties=getCache().get(thisOClass);
      if (refProperties != null && refProperties.size() > 0) {
        String[] changedFields=doc.getDirtyFields();
        for (        String field : changedFields) {
          OProperty changedProperty=thisOClass.getProperty(field);
          if (refProperties.contains(changedProperty)) {
            OProperty inverseProperty=CustomAttributes.PROP_INVERSE.getValue(changedProperty);
            if (changedProperty.getType().isMultiValue()) {
              OMultiValueChangeTimeLine<Object,Object> timeline=doc.getCollectionTimeLine(field);
              if (timeline != null) {
                List<OMultiValueChangeEvent<Object,Object>> events=timeline.getMultiValueChangeEvents();
                for (                OMultiValueChangeEvent<Object,Object> event : events) {
                  OIdentifiable toAddTo=null;
                  OIdentifiable toRemoveFrom=null;
switch (event.getChangeType()) {
case ADD:
                    toAddTo=(OIdentifiable)event.getValue();
                  break;
case UPDATE:
                toAddTo=(OIdentifiable)event.getValue();
              toRemoveFrom=(OIdentifiable)event.getOldValue();
            break;
case REMOVE:
          toRemoveFrom=(OIdentifiable)event.getOldValue();
        break;
    }
    if (toAddTo != null)     addLink((ODocument)toAddTo.getRecord(),inverseProperty,doc);
    if (toRemoveFrom != null)     removeLink((ODocument)toRemoveFrom.getRecord(),inverseProperty,doc);
  }
}
 else {
  Object original=doc.getOriginalValue(field);
  Object current=doc.field(field);
  if (original != null && original instanceof Iterable) {
    for (    Object originaIdentifiable : (Iterable<?>)original) {
      if (originaIdentifiable != null && originaIdentifiable instanceof OIdentifiable)       removeLink((ODocument)((OIdentifiable)originaIdentifiable).getRecord(),inverseProperty,doc);
    }
  }
  if (current != null && current instanceof Iterable) {
    for (    Object currentIdentifiable : (Iterable<?>)current) {
      if (currentIdentifiable != null && currentIdentifiable instanceof OIdentifiable)       addLink((ODocument)((OIdentifiable)currentIdentifiable).getRecord(),inverseProperty,doc);
    }
  }
}
}
 else {
Object original=doc.getOriginalValue(field);
Object current=doc.field(field);
if (original != null && original instanceof OIdentifiable) removeLink((ODocument)((OIdentifiable)original).getRecord(),inverseProperty,doc);
if (current != null && current instanceof OIdentifiable) addLink((ODocument)((OIdentifiable)current).getRecord(),inverseProperty,doc);
}
}
}
}
}
 catch (ExecutionException e) {
LOG.error("String_Node_Str",e);
}
 finally {
exit();
}
}
}