Program: 12495
Project: 12495
Buggy source:
/** 
 * Copy all objects to an a new SBOL Document and change the URI prefix/version of each object
 * @param URIPrefix new URI prefix
 * @param version new version
 * @return new SBOL document with changed URI prefix
 * @throws SBOLValidationException
 */
public SBOLDocument changeURIPrefixVersion(String URIPrefix,String version) throws SBOLValidationException {
  SBOLDocument document=createCopy(URIPrefix,null,version);
  document.setDefaultURIprefix(URIPrefix);
  for (  Collection collection : getCollections()) {
    Set<URI> members=new HashSet<URI>();
    for (    TopLevel member : collection.getMembers()) {
      if (member instanceof Sequence) {
        Sequence tl=document.getSequence(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof ComponentDefinition) {
        ComponentDefinition tl=document.getComponentDefinition(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof ModuleDefinition) {
        ModuleDefinition tl=document.getModuleDefinition(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof Model) {
        Model tl=document.getModel(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof GenericTopLevel) {
        GenericTopLevel tl=document.getGenericTopLevel(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof Collection) {
        Collection tl=document.getCollection(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
    }
    document.getCollection(collection.getDisplayId(),collection.getVersion()).setMembers(members);
  }
  for (  ComponentDefinition componentDefinition : getComponentDefinitions()) {
    ComponentDefinition docCD=document.getComponentDefinition(componentDefinition.getDisplayId(),version != null ? version : componentDefinition.getVersion());
    for (    Component component : componentDefinition.getComponents()) {
      ComponentDefinition cd=component.getDefinition();
      ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
      Component docComp=docCD.getComponent(component.getDisplayId());
      docComp.setDefinition(docRefCD.getIdentity());
      for (      MapsTo mapsTo : component.getMapsTos()) {
        Component remoteComponent=(Component)mapsTo.getRemote();
        Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
        docComp.getMapsTo(mapsTo.getDisplayId()).setRemote(docRemoteComponent.getIdentity());
      }
    }
    Set<URI> sequences=new HashSet<URI>();
    for (    Sequence sequence : componentDefinition.getSequences()) {
      Sequence docSeq=document.getSequence(sequence.getDisplayId(),version != null ? version : sequence.getVersion());
      sequences.add(docSeq.getIdentity());
    }
    docCD.setSequences(sequences);
  }
  for (  ModuleDefinition moduleDefinition : getModuleDefinitions()) {
    ModuleDefinition docMD=document.getModuleDefinition(moduleDefinition.getDisplayId(),version != null ? version : moduleDefinition.getVersion());
    for (    FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
      ComponentDefinition cd=functionalComponent.getDefinition();
      ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
      FunctionalComponent docComp=docMD.getFunctionalComponent(functionalComponent.getDisplayId());
      docComp.setDefinition(docRefCD.getIdentity());
      for (      MapsTo mapsTo : functionalComponent.getMapsTos()) {
        ComponentInstance remoteComponent=mapsTo.getRemote();
        Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
        docComp.getMapsTo(mapsTo.getDisplayId()).setRemote(docRemoteComponent.getIdentity());
      }
    }
    for (    Module module : moduleDefinition.getModules()) {
      ModuleDefinition md=module.getDefinition();
      ModuleDefinition docRefMD=document.getModuleDefinition(md.getDisplayId(),version != null ? version : md.getVersion());
      Module docModule=docMD.getModule(module.getDisplayId());
      docModule.setDefinition(docRefMD.getIdentity());
      for (      MapsTo mapsTo : module.getMapsTos()) {
        ComponentInstance remoteComponent=mapsTo.getRemote();
        FunctionalComponent docRemoteComponent=docRefMD.getFunctionalComponent(remoteComponent.getDisplayId());
        docModule.getMapsTo(mapsTo.getDisplayId()).setRemote(docRemoteComponent.getIdentity());
      }
    }
    Set<URI> models=new HashSet<URI>();
    for (    Model model : moduleDefinition.getModels()) {
      Model docMod=document.getModel(model.getDisplayId(),version != null ? version : model.getVersion());
      models.add(docMod.getIdentity());
    }
    docMD.setModels(models);
  }
  return document;
}

Fixed version (ground truth):
/** 
 * Copy all objects to an a new SBOL Document and change the URI prefix/version of each object
 * @param URIPrefix new URI prefix
 * @param version new version
 * @return new SBOL document with changed URI prefix
 * @throws SBOLValidationException
 */
public SBOLDocument changeURIPrefixVersion(String URIPrefix,String version) throws SBOLValidationException {
  SBOLDocument document=createCopy(URIPrefix,null,version);
  document.setDefaultURIprefix(URIPrefix);
  for (  Collection collection : getCollections()) {
    Set<URI> members=new HashSet<URI>();
    for (    TopLevel member : collection.getMembers()) {
      if (member instanceof Sequence) {
        Sequence tl=document.getSequence(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof ComponentDefinition) {
        ComponentDefinition tl=document.getComponentDefinition(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof ModuleDefinition) {
        ModuleDefinition tl=document.getModuleDefinition(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof Model) {
        Model tl=document.getModel(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof GenericTopLevel) {
        GenericTopLevel tl=document.getGenericTopLevel(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
      if (member instanceof Collection) {
        Collection tl=document.getCollection(member.getDisplayId(),version != null ? version : member.getVersion());
        members.add(tl.getIdentity());
      }
    }
    document.getCollection(collection.getDisplayId(),version != null ? version : collection.getVersion()).setMembers(members);
  }
  for (  ComponentDefinition componentDefinition : getComponentDefinitions()) {
    ComponentDefinition docCD=document.getComponentDefinition(componentDefinition.getDisplayId(),version != null ? version : componentDefinition.getVersion());
    for (    Component component : componentDefinition.getComponents()) {
      ComponentDefinition cd=component.getDefinition();
      ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
      Component docComp=docCD.getComponent(component.getDisplayId());
      docComp.setDefinition(docRefCD.getIdentity());
      for (      MapsTo mapsTo : component.getMapsTos()) {
        Component remoteComponent=(Component)mapsTo.getRemote();
        Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
        docComp.getMapsTo(mapsTo.getDisplayId()).setRemote(docRemoteComponent.getIdentity());
      }
    }
    Set<URI> sequences=new HashSet<URI>();
    for (    Sequence sequence : componentDefinition.getSequences()) {
      Sequence docSeq=document.getSequence(sequence.getDisplayId(),version != null ? version : sequence.getVersion());
      sequences.add(docSeq.getIdentity());
    }
    docCD.setSequences(sequences);
  }
  for (  ModuleDefinition moduleDefinition : getModuleDefinitions()) {
    ModuleDefinition docMD=document.getModuleDefinition(moduleDefinition.getDisplayId(),version != null ? version : moduleDefinition.getVersion());
    for (    FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
      ComponentDefinition cd=functionalComponent.getDefinition();
      ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
      FunctionalComponent docComp=docMD.getFunctionalComponent(functionalComponent.getDisplayId());
      docComp.setDefinition(docRefCD.getIdentity());
      for (      MapsTo mapsTo : functionalComponent.getMapsTos()) {
        ComponentInstance remoteComponent=mapsTo.getRemote();
        Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
        docComp.getMapsTo(mapsTo.getDisplayId()).setRemote(docRemoteComponent.getIdentity());
      }
    }
    for (    Module module : moduleDefinition.getModules()) {
      ModuleDefinition md=module.getDefinition();
      ModuleDefinition docRefMD=document.getModuleDefinition(md.getDisplayId(),version != null ? version : md.getVersion());
      Module docModule=docMD.getModule(module.getDisplayId());
      docModule.setDefinition(docRefMD.getIdentity());
      for (      MapsTo mapsTo : module.getMapsTos()) {
        ComponentInstance remoteComponent=mapsTo.getRemote();
        FunctionalComponent docRemoteComponent=docRefMD.getFunctionalComponent(remoteComponent.getDisplayId());
        docModule.getMapsTo(mapsTo.getDisplayId()).setRemote(docRemoteComponent.getIdentity());
      }
    }
    Set<URI> models=new HashSet<URI>();
    for (    Model model : moduleDefinition.getModels()) {
      Model docMod=document.getModel(model.getDisplayId(),version != null ? version : model.getVersion());
      models.add(docMod.getIdentity());
    }
    docMD.setModels(models);
  }
  return document;
}