Program: 12399
Project: 12399
Buggy source:
/** 
 * @param document document to copy recursively into
 * @param topLevel topLevel that is being recursively copied from
 * @throws SBOLValidationException if an SBOL validation rule violation occurred in {@link SBOLDocument#createCopy(TopLevel)}.
 */
public void createRecursiveCopy(SBOLDocument document,TopLevel topLevel) throws SBOLValidationException {
  if (document.getTopLevelLocalOnly(topLevel.getIdentity()) != null)   return;
  for (  URI wasDerivedFromURI : topLevel.getWasDerivedFroms()) {
    TopLevel wasDerivedFrom=document.getTopLevelLocalOnly(wasDerivedFromURI);
    if (wasDerivedFrom != null) {
      createRecursiveCopy(document,wasDerivedFrom);
    }
  }
  for (  URI wasGeneratedByURI : topLevel.getWasGeneratedBys()) {
    TopLevel wasGeneratedBy=document.getTopLevelLocalOnly(wasGeneratedByURI);
    if (wasGeneratedBy != null) {
      createRecursiveCopy(document,wasGeneratedBy);
    }
  }
  if (topLevel instanceof GenericTopLevel || topLevel instanceof Sequence || topLevel instanceof Model|| topLevel instanceof Plan|| topLevel instanceof Agent) {
    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 CombinatorialDerivation) {
    if (((CombinatorialDerivation)topLevel).getTemplate() != null) {
      createRecursiveCopy(document,((CombinatorialDerivation)topLevel).getTemplate());
    }
    for (    VariableComponent variableComponent : ((CombinatorialDerivation)topLevel).getVariableComponents()) {
      for (      Collection collection : variableComponent.getVariantCollections()) {
        createRecursiveCopy(document,collection);
      }
      for (      ComponentDefinition componentDefinition : variableComponent.getVariants()) {
        createRecursiveCopy(document,componentDefinition);
      }
      for (      CombinatorialDerivation combinatorialDerivation : variableComponent.getVariantDerivations()) {
        createRecursiveCopy(document,combinatorialDerivation);
      }
    }
    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);
  }
 else   if (topLevel instanceof Activity) {
    for (    Association association : ((Activity)topLevel).getAssociations()) {
      if (association.getAgent() != null) {
        createRecursiveCopy(document,association.getAgent());
      }
      if (association.getPlan() != null) {
        createRecursiveCopy(document,association.getPlan());
      }
    }
    for (    Usage usage : ((Activity)topLevel).getUsages()) {
      if (usage.getEntity() != null) {
        createRecursiveCopy(document,usage.getEntity());
      }
    }
    document.createCopy(topLevel);
  }
  for (  Annotation annotation : topLevel.getAnnotations()) {
    if (annotation.isURIValue()) {
      TopLevel gtl=getTopLevelLocalOnly(annotation.getURIValue());
      if (gtl != null)       createRecursiveCopy(document,gtl);
    }
 else     if (annotation.isNestedAnnotations()) {
      for (      Annotation nestedAnnotation : annotation.getAnnotations()) {
        createRecursiveCopy(document,nestedAnnotation);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * @param document document to copy recursively into
 * @param topLevel topLevel that is being recursively copied from
 * @throws SBOLValidationException if an SBOL validation rule violation occurred in {@link SBOLDocument#createCopy(TopLevel)}.
 */
public void createRecursiveCopy(SBOLDocument document,TopLevel topLevel) throws SBOLValidationException {
  if (document.getTopLevelLocalOnly(topLevel.getIdentity()) != null)   return;
  for (  URI wasDerivedFromURI : topLevel.getWasDerivedFroms()) {
    TopLevel wasDerivedFrom=getTopLevelLocalOnly(wasDerivedFromURI);
    if (wasDerivedFrom != null) {
      createRecursiveCopy(document,wasDerivedFrom);
    }
  }
  for (  URI wasGeneratedByURI : topLevel.getWasGeneratedBys()) {
    TopLevel wasGeneratedBy=getTopLevelLocalOnly(wasGeneratedByURI);
    if (wasGeneratedBy != null) {
      createRecursiveCopy(document,wasGeneratedBy);
    }
  }
  if (topLevel instanceof GenericTopLevel || topLevel instanceof Sequence || topLevel instanceof Model|| topLevel instanceof Plan|| topLevel instanceof Agent) {
    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 CombinatorialDerivation) {
    if (((CombinatorialDerivation)topLevel).getTemplate() != null) {
      createRecursiveCopy(document,((CombinatorialDerivation)topLevel).getTemplate());
    }
    for (    VariableComponent variableComponent : ((CombinatorialDerivation)topLevel).getVariableComponents()) {
      for (      Collection collection : variableComponent.getVariantCollections()) {
        createRecursiveCopy(document,collection);
      }
      for (      ComponentDefinition componentDefinition : variableComponent.getVariants()) {
        createRecursiveCopy(document,componentDefinition);
      }
      for (      CombinatorialDerivation combinatorialDerivation : variableComponent.getVariantDerivations()) {
        createRecursiveCopy(document,combinatorialDerivation);
      }
    }
    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);
  }
 else   if (topLevel instanceof Activity) {
    for (    Association association : ((Activity)topLevel).getAssociations()) {
      if (association.getAgent() != null) {
        createRecursiveCopy(document,association.getAgent());
      }
      if (association.getPlan() != null) {
        createRecursiveCopy(document,association.getPlan());
      }
    }
    for (    Usage usage : ((Activity)topLevel).getUsages()) {
      if (usage.getEntity() != null) {
        createRecursiveCopy(document,usage.getEntity());
      }
    }
    document.createCopy(topLevel);
  }
  for (  Annotation annotation : topLevel.getAnnotations()) {
    if (annotation.isURIValue()) {
      TopLevel gtl=getTopLevelLocalOnly(annotation.getURIValue());
      if (gtl != null)       createRecursiveCopy(document,gtl);
    }
 else     if (annotation.isNestedAnnotations()) {
      for (      Annotation nestedAnnotation : annotation.getAnnotations()) {
        createRecursiveCopy(document,nestedAnnotation);
      }
    }
  }
}