Program: 12482
Project: 12482
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 (    URI memberURI : collection.getMemberURIs()) {
      TopLevel member=getTopLevel(memberURI);
      if (member == null) {
        members.add(memberURI);
      }
 else {
        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());
        }
      }
    }
    Collection docCol=document.getCollection(collection.getDisplayId(),version != null ? version : collection.getVersion());
    docCol.setMembers(members);
    changeURIPrefixVersion(docCol,URIPrefix,version);
  }
  for (  ComponentDefinition componentDefinition : getComponentDefinitions()) {
    ComponentDefinition docCD=document.getComponentDefinition(componentDefinition.getDisplayId(),version != null ? version : componentDefinition.getVersion());
    changeURIPrefixVersion(docCD,URIPrefix,version);
    for (    Component component : componentDefinition.getComponents()) {
      Component docComp=docCD.getComponent(component.getDisplayId());
      ComponentDefinition cd=component.getDefinition();
      if (cd == null) {
        docComp.setDefinition(component.getDefinitionURI());
      }
 else {
        ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
        docComp.setDefinition(docRefCD.getIdentity());
      }
      changeURIPrefixVersion(docComp,URIPrefix,version);
      for (      MapsTo mapsTo : component.getMapsTos()) {
        MapsTo docMapsTo=docComp.getMapsTo(mapsTo.getDisplayId());
        Component remoteComponent=(Component)mapsTo.getRemote();
        if (remoteComponent == null) {
          docMapsTo.setRemote(mapsTo.getRemoteURI());
        }
 else {
          ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
          Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
          docMapsTo.setRemote(docRemoteComponent.getIdentity());
        }
        changeURIPrefixVersion(docMapsTo,URIPrefix,version);
      }
    }
    for (    SequenceAnnotation sa : docCD.getSequenceAnnotations()) {
      changeURIPrefixVersion(sa,URIPrefix,version);
    }
    for (    SequenceConstraint sc : docCD.getSequenceConstraints()) {
      changeURIPrefixVersion(sc,URIPrefix,version);
    }
    Set<URI> sequences=new HashSet<URI>();
    for (    URI sequenceURI : componentDefinition.getSequenceURIs()) {
      Sequence sequence=getSequence(sequenceURI);
      if (sequence == null) {
        sequences.add(sequenceURI);
      }
 else {
        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());
    changeURIPrefixVersion(docMD,URIPrefix,version);
    for (    FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
      FunctionalComponent docComp=docMD.getFunctionalComponent(functionalComponent.getDisplayId());
      ComponentDefinition cd=functionalComponent.getDefinition();
      if (cd == null) {
        docComp.setDefinition(functionalComponent.getDefinitionURI());
      }
 else {
        ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
        docComp.setDefinition(docRefCD.getIdentity());
      }
      changeURIPrefixVersion(docComp,URIPrefix,version);
      for (      MapsTo mapsTo : functionalComponent.getMapsTos()) {
        MapsTo docMapsTo=docComp.getMapsTo(mapsTo.getDisplayId());
        ComponentInstance remoteComponent=mapsTo.getRemote();
        if (remoteComponent == null) {
          docMapsTo.setRemote(mapsTo.getRemoteURI());
        }
 else {
          ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
          Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
          docMapsTo.setRemote(docRemoteComponent.getIdentity());
        }
        changeURIPrefixVersion(docMapsTo,URIPrefix,version);
      }
    }
    for (    Module module : moduleDefinition.getModules()) {
      Module docModule=docMD.getModule(module.getDisplayId());
      ModuleDefinition md=module.getDefinition();
      if (md == null) {
        docModule.setDefinition(module.getDefinitionURI());
      }
 else {
        ModuleDefinition docRefMD=document.getModuleDefinition(md.getDisplayId(),version != null ? version : md.getVersion());
        docModule.setDefinition(docRefMD.getIdentity());
      }
      changeURIPrefixVersion(docModule,URIPrefix,version);
      for (      MapsTo mapsTo : module.getMapsTos()) {
        MapsTo docMapsTo=docModule.getMapsTo(mapsTo.getDisplayId());
        ComponentInstance remoteComponent=mapsTo.getRemote();
        if (remoteComponent == null) {
          docMapsTo.setRemote(mapsTo.getRemoteURI());
        }
 else {
          ModuleDefinition docRefMD=document.getModuleDefinition(md.getDisplayId(),version != null ? version : md.getVersion());
          FunctionalComponent docRemoteComponent=docRefMD.getFunctionalComponent(remoteComponent.getDisplayId());
          docMapsTo.setRemote(docRemoteComponent.getIdentity());
        }
        changeURIPrefixVersion(docMapsTo,URIPrefix,version);
      }
    }
    for (    Interaction interaction : docMD.getInteractions()) {
      changeURIPrefixVersion(interaction,URIPrefix,version);
      for (      Participation participation : interaction.getParticipations()) {
        changeURIPrefixVersion(participation,URIPrefix,version);
      }
    }
    Set<URI> models=new HashSet<URI>();
    for (    URI modelURI : moduleDefinition.getModelURIs()) {
      Model model=getModel(modelURI);
      if (model == null) {
        models.add(modelURI);
      }
 else {
        Model docMod=document.getModel(model.getDisplayId(),version != null ? version : model.getVersion());
        models.add(docMod.getIdentity());
      }
    }
    docMD.setModels(models);
  }
  for (  Model model : document.getModels()) {
    changeURIPrefixVersion(model,URIPrefix,version);
  }
  for (  Sequence sequence : document.getSequences()) {
    changeURIPrefixVersion(sequence,URIPrefix,version);
  }
  for (  GenericTopLevel genericTopLevel : document.getGenericTopLevels()) {
    changeURIPrefixVersion(genericTopLevel,URIPrefix,version);
  }
  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 (    URI memberURI : collection.getMemberURIs()) {
      TopLevel member=getTopLevel(memberURI);
      if (member == null) {
        members.add(memberURI);
      }
 else {
        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());
        }
      }
    }
    Collection docCol=document.getCollection(collection.getDisplayId(),version != null ? version : collection.getVersion());
    docCol.setMembers(members);
    changeURIPrefixVersion(docCol,URIPrefix,version);
  }
  for (  ComponentDefinition componentDefinition : getComponentDefinitions()) {
    ComponentDefinition docCD=document.getComponentDefinition(componentDefinition.getDisplayId(),version != null ? version : componentDefinition.getVersion());
    changeURIPrefixVersion(docCD,URIPrefix,version);
    for (    Component component : componentDefinition.getComponents()) {
      Component docComp=docCD.getComponent(component.getDisplayId());
      ComponentDefinition cd=component.getDefinition();
      if (cd == null) {
        docComp.setDefinition(component.getDefinitionURI());
      }
 else {
        ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
        docComp.setDefinition(docRefCD.getIdentity());
      }
      changeURIPrefixVersion(docComp,URIPrefix,version);
      for (      MapsTo mapsTo : component.getMapsTos()) {
        MapsTo docMapsTo=docComp.getMapsTo(mapsTo.getDisplayId());
        Component remoteComponent=(Component)mapsTo.getRemote();
        if (remoteComponent == null) {
          docMapsTo.setRemote(mapsTo.getRemoteURI());
        }
 else {
          ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
          Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
          docMapsTo.setRemote(docRemoteComponent.getIdentity());
        }
        changeURIPrefixVersion(docMapsTo,URIPrefix,version);
      }
    }
    for (    SequenceAnnotation sa : docCD.getSequenceAnnotations()) {
      for (      Location loc : sa.getLocations()) {
        changeURIPrefixVersion(loc,URIPrefix,version);
      }
      changeURIPrefixVersion(sa,URIPrefix,version);
    }
    for (    SequenceConstraint sc : docCD.getSequenceConstraints()) {
      changeURIPrefixVersion(sc,URIPrefix,version);
    }
    Set<URI> sequences=new HashSet<URI>();
    for (    URI sequenceURI : componentDefinition.getSequenceURIs()) {
      Sequence sequence=getSequence(sequenceURI);
      if (sequence == null) {
        sequences.add(sequenceURI);
      }
 else {
        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());
    changeURIPrefixVersion(docMD,URIPrefix,version);
    for (    FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
      FunctionalComponent docComp=docMD.getFunctionalComponent(functionalComponent.getDisplayId());
      ComponentDefinition cd=functionalComponent.getDefinition();
      if (cd == null) {
        docComp.setDefinition(functionalComponent.getDefinitionURI());
      }
 else {
        ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
        docComp.setDefinition(docRefCD.getIdentity());
      }
      changeURIPrefixVersion(docComp,URIPrefix,version);
      for (      MapsTo mapsTo : functionalComponent.getMapsTos()) {
        MapsTo docMapsTo=docComp.getMapsTo(mapsTo.getDisplayId());
        ComponentInstance remoteComponent=mapsTo.getRemote();
        if (remoteComponent == null) {
          docMapsTo.setRemote(mapsTo.getRemoteURI());
        }
 else {
          ComponentDefinition docRefCD=document.getComponentDefinition(cd.getDisplayId(),version != null ? version : cd.getVersion());
          Component docRemoteComponent=docRefCD.getComponent(remoteComponent.getDisplayId());
          docMapsTo.setRemote(docRemoteComponent.getIdentity());
        }
        changeURIPrefixVersion(docMapsTo,URIPrefix,version);
      }
    }
    for (    Module module : moduleDefinition.getModules()) {
      Module docModule=docMD.getModule(module.getDisplayId());
      ModuleDefinition md=module.getDefinition();
      if (md == null) {
        docModule.setDefinition(module.getDefinitionURI());
      }
 else {
        ModuleDefinition docRefMD=document.getModuleDefinition(md.getDisplayId(),version != null ? version : md.getVersion());
        docModule.setDefinition(docRefMD.getIdentity());
      }
      changeURIPrefixVersion(docModule,URIPrefix,version);
      for (      MapsTo mapsTo : module.getMapsTos()) {
        MapsTo docMapsTo=docModule.getMapsTo(mapsTo.getDisplayId());
        ComponentInstance remoteComponent=mapsTo.getRemote();
        if (remoteComponent == null) {
          docMapsTo.setRemote(mapsTo.getRemoteURI());
        }
 else {
          ModuleDefinition docRefMD=document.getModuleDefinition(md.getDisplayId(),version != null ? version : md.getVersion());
          FunctionalComponent docRemoteComponent=docRefMD.getFunctionalComponent(remoteComponent.getDisplayId());
          docMapsTo.setRemote(docRemoteComponent.getIdentity());
        }
        changeURIPrefixVersion(docMapsTo,URIPrefix,version);
      }
    }
    for (    Interaction interaction : docMD.getInteractions()) {
      changeURIPrefixVersion(interaction,URIPrefix,version);
      for (      Participation participation : interaction.getParticipations()) {
        changeURIPrefixVersion(participation,URIPrefix,version);
      }
    }
    Set<URI> models=new HashSet<URI>();
    for (    URI modelURI : moduleDefinition.getModelURIs()) {
      Model model=getModel(modelURI);
      if (model == null) {
        models.add(modelURI);
      }
 else {
        Model docMod=document.getModel(model.getDisplayId(),version != null ? version : model.getVersion());
        models.add(docMod.getIdentity());
      }
    }
    docMD.setModels(models);
  }
  for (  Model model : document.getModels()) {
    changeURIPrefixVersion(model,URIPrefix,version);
  }
  for (  Sequence sequence : document.getSequences()) {
    changeURIPrefixVersion(sequence,URIPrefix,version);
  }
  for (  GenericTopLevel genericTopLevel : document.getGenericTopLevels()) {
    changeURIPrefixVersion(genericTopLevel,URIPrefix,version);
  }
  return document;
}