Program: 21651
Project: 21651
Buggy source:
public void internalCopyInto(OTDataObject source,OTDataObject dest,int maxDepth) throws Exception {
  toBeCopied.add(new CopyEntry(source,maxDepth,dest));
  OTDatabase otDb=dest.getDatabase();
  int currentIndex=0;
  while (currentIndex < toBeCopied.size()) {
    CopyEntry entry=(CopyEntry)toBeCopied.get(currentIndex);
    OTDataObject original=entry.original;
    OTDataObject copy=entry.copy;
    if (copy == null) {
      copy=otDb.createDataObject();
    }
    String[] keys=original.getResourceKeys();
    for (int i=0; i < keys.length; i++) {
      Object resource=original.getResource(keys[i]);
      if (resource instanceof OTDataList) {
        OTDataList copyList=(OTDataList)copy.getResourceCollection(keys[i],OTDataList.class);
        OTDataList list=(OTDataList)resource;
        copyList.removeAll();
        for (int j=0; j < list.size(); j++) {
          Object listItem=list.get(j);
          listItem=handleChild(listItem,entry.maxDepth);
          copyList.add(listItem);
        }
      }
 else       if (resource instanceof OTDataMap) {
        OTDataMap copyMap=(OTDataMap)copy.getResourceCollection(keys[i],OTDataMap.class);
        OTDataMap map=(OTDataMap)resource;
        copyMap.removeAll();
        String[] mapKeys=map.getKeys();
        for (int j=0; j < mapKeys.length; j++) {
          Object item=map.get(mapKeys[j]);
          item=handleChild(item,entry.maxDepth);
          copyMap.put(mapKeys[j],item);
        }
      }
 else {
        resource=handleChild(resource,entry.maxDepth);
        copy.setResource(keys[i],resource);
      }
    }
    currentIndex++;
  }
}

Fixed version (ground truth):
public void internalCopyInto(OTDataObject source,OTDataObject dest,int maxDepth) throws Exception {
  toBeCopied.add(new CopyEntry(source,maxDepth,dest));
  OTDatabase otDb=dest.getDatabase();
  int currentIndex=0;
  while (currentIndex < toBeCopied.size()) {
    CopyEntry entry=(CopyEntry)toBeCopied.get(currentIndex);
    OTDataObject original=entry.original;
    OTDataObject copy=entry.copy;
    if (copy == null) {
      copy=otDb.createDataObject();
    }
    String[] keys=original.getResourceKeys();
    Vector secondPassKeys=new Vector();
    for (int i=0; i < keys.length; i++) {
      Object resource=original.getResource(keys[i]);
      if (resource instanceof OTDataList) {
        OTDataList copyList=(OTDataList)copy.getResourceCollection(keys[i],OTDataList.class);
        OTDataList list=(OTDataList)resource;
        copyList.removeAll();
        for (int j=0; j < list.size(); j++) {
          Object listItem=list.get(j);
          listItem=handleChild(listItem,entry.maxDepth);
          copyList.add(listItem);
        }
      }
 else       if (resource instanceof OTDataMap) {
        OTDataMap copyMap=(OTDataMap)copy.getResourceCollection(keys[i],OTDataMap.class);
        OTDataMap map=(OTDataMap)resource;
        copyMap.removeAll();
        String[] mapKeys=map.getKeys();
        for (int j=0; j < mapKeys.length; j++) {
          Object item=map.get(mapKeys[j]);
          item=handleChild(item,entry.maxDepth);
          copyMap.put(mapKeys[j],item);
        }
      }
 else       if (resource instanceof OTXMLString) {
        secondPassKeys.add(keys[i]);
      }
 else {
        resource=handleChild(resource,entry.maxDepth);
        copy.setResource(keys[i],resource);
      }
    }
    for (int i=0; i < secondPassKeys.size(); i++) {
      String key=(String)secondPassKeys.get(i);
      Object resource=original.getResource(key);
      System.out.println("String_Node_Str" + key);
      OTXMLString xmlString=(OTXMLString)resource;
      Pattern pattern=Pattern.compile("String_Node_Str");
      Matcher matcher=pattern.matcher(xmlString.getContent());
      StringBuffer copiedStringBuf=new StringBuffer();
      while (matcher.find()) {
        String otidStr=matcher.group(1);
        OTID otid=OTIDFactory.createOTID(otidStr);
        CopyEntry copyEntry=getCopyEntry(otid);
        Object copiedId=null;
        if (copyEntry != null) {
          copiedId=copyEntry.copy.getGlobalId();
        }
 else {
          if (orphanList == null) {
            System.err.println("String_Node_Str" + "String_Node_Str");
            System.err.println("String_Node_Str" + otid);
            System.err.println("String_Node_Str" + original);
            System.err.println("String_Node_Str" + key);
            copiedId=otid;
          }
 else {
            copiedId=handleChild(otid,entry.maxDepth);
            orphanList.add(copiedId);
          }
        }
        matcher.appendReplacement(copiedStringBuf,"String_Node_Str" + copiedId + "String_Node_Str");
      }
      matcher.appendTail(copiedStringBuf);
      OTXMLString copiedXmlString=new OTXMLString(copiedStringBuf.toString());
      copy.setResource(key,copiedXmlString);
    }
    currentIndex++;
  }
}