Program: 12382
Project: 12382
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;
  document.createCopy(topLevel);
  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) {
  }
 else   if (topLevel instanceof Collection) {
    for (    TopLevel member : ((Collection)topLevel).getMembers()) {
      createRecursiveCopy(document,member);
    }
  }
 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);
    }
  }
 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);
      }
    }
  }
 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()) {
      createRecursiveCopy(document,model);
    }
  }
 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());
      }
    }
  }
  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;
  document.createCopy(topLevel);
  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|| topLevel instanceof Implementation) {
  }
 else   if (topLevel instanceof Collection) {
    for (    TopLevel member : ((Collection)topLevel).getMembers()) {
      createRecursiveCopy(document,member);
    }
  }
 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);
    }
  }
 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);
      }
    }
  }
 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()) {
      createRecursiveCopy(document,model);
    }
  }
 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());
      }
    }
  }
  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);
      }
    }
  }
}