Program: 12471
Project: 12471
Buggy source:
/** 
 * @param document
 * @param topLevel
 * @throws SBOLValidationException if an SBOL validation rule violation occurred in {@link SBOLDocument#createCopy(TopLevel)}.
 */
private void createRecursiveCopy(SBOLDocument document,TopLevel topLevel) throws SBOLValidationException {
  if (document.getTopLevel(topLevel.getIdentity()) != null)   return;
  for (  Annotation annotation : topLevel.getAnnotations()) {
    if (annotation.isURIValue()) {
      TopLevel gtl=getTopLevel(annotation.getURIValue());
      if (gtl != null)       createRecursiveCopy(document,gtl);
    }
 else     if (annotation.isNestedAnnotations()) {
      for (      Annotation nestedAnnotation : annotation.getAnnotations()) {
        createRecursiveCopy(document,nestedAnnotation);
      }
    }
  }
  if (topLevel instanceof GenericTopLevel || topLevel instanceof Sequence || topLevel instanceof Model) {
    document.createCopy(topLevel);
  }
 else   if (topLevel instanceof Collection) {
    for (    TopLevel member : ((Collection)topLevel).getMembers()) {
      createRecursiveCopy(document,member);
    }
    document.createCopy(topLevel);
  }
 else   if (topLevel instanceof ComponentDefinition) {
    for (    Component component : ((ComponentDefinition)topLevel).getComponents()) {
      if (component.getDefinition() != null) {
        createRecursiveCopy(document,component.getDefinition());
      }
    }
    for (    TopLevel sequence : ((ComponentDefinition)topLevel).getSequences()) {
      createRecursiveCopy(document,sequence);
    }
    document.createCopy(topLevel);
  }
 else   if (topLevel instanceof ModuleDefinition) {
    for (    FunctionalComponent functionalComponent : ((ModuleDefinition)topLevel).getFunctionalComponents()) {
      if (functionalComponent.getDefinition() != null) {
        createRecursiveCopy(document,functionalComponent.getDefinition());
      }
    }
    for (    Module module : ((ModuleDefinition)topLevel).getModules()) {
      if (module.getDefinition() != null) {
        createRecursiveCopy(document,module.getDefinition());
      }
    }
    for (    Model model : ((ModuleDefinition)topLevel).getModels()) {
      if (document.getModel(model.getIdentity()) != null)       continue;
      document.createCopy(model);
    }
    document.createCopy(topLevel);
  }
}

Fixed version (ground truth):
/** 
 * @param document
 * @param topLevel
 * @throws SBOLValidationException if an SBOL validation rule violation occurred in {@link SBOLDocument#createCopy(TopLevel)}.
 */
private void createRecursiveCopy(SBOLDocument document,TopLevel topLevel) throws SBOLValidationException {
  if (document.getTopLevel(topLevel.getIdentity()) != null)   return;
  if (topLevel instanceof GenericTopLevel || topLevel instanceof Sequence || topLevel instanceof Model) {
    document.createCopy(topLevel);
  }
 else   if (topLevel instanceof Collection) {
    for (    TopLevel member : ((Collection)topLevel).getMembers()) {
      createRecursiveCopy(document,member);
    }
    document.createCopy(topLevel);
  }
 else   if (topLevel instanceof ComponentDefinition) {
    for (    Component component : ((ComponentDefinition)topLevel).getComponents()) {
      if (component.getDefinition() != null) {
        createRecursiveCopy(document,component.getDefinition());
      }
    }
    for (    TopLevel sequence : ((ComponentDefinition)topLevel).getSequences()) {
      createRecursiveCopy(document,sequence);
    }
    document.createCopy(topLevel);
  }
 else   if (topLevel instanceof ModuleDefinition) {
    for (    FunctionalComponent functionalComponent : ((ModuleDefinition)topLevel).getFunctionalComponents()) {
      if (functionalComponent.getDefinition() != null) {
        createRecursiveCopy(document,functionalComponent.getDefinition());
      }
    }
    for (    Module module : ((ModuleDefinition)topLevel).getModules()) {
      if (module.getDefinition() != null) {
        createRecursiveCopy(document,module.getDefinition());
      }
    }
    for (    Model model : ((ModuleDefinition)topLevel).getModels()) {
      if (document.getModel(model.getIdentity()) != null)       continue;
      document.createCopy(model);
    }
    document.createCopy(topLevel);
  }
  for (  Annotation annotation : topLevel.getAnnotations()) {
    if (annotation.isURIValue()) {
      TopLevel gtl=getTopLevel(annotation.getURIValue());
      if (gtl != null)       createRecursiveCopy(document,gtl);
    }
 else     if (annotation.isNestedAnnotations()) {
      for (      Annotation nestedAnnotation : annotation.getAnnotations()) {
        createRecursiveCopy(document,nestedAnnotation);
      }
    }
  }
}