Program: 12462
Project: 12462
Buggy source:
private void updateReferences(HashMap<URI,URI> uriMap) throws SBOLValidationException {
  for (  Collection collection : getCollections()) {
    for (    URI memberURI : collection.getMemberURIs()) {
      if (uriMap.get(memberURI) != null) {
        collection.removeMember(memberURI);
        collection.addMember(uriMap.get(memberURI));
      }
    }
    updateReferences(collection,uriMap);
  }
  for (  ComponentDefinition componentDefinition : getComponentDefinitions()) {
    updateReferences(componentDefinition,uriMap);
    for (    Component component : componentDefinition.getComponents()) {
      if (uriMap.get(component.getDefinitionURI()) != null) {
        component.setDefinition(uriMap.get(component.getDefinitionURI()));
        for (        MapsTo mapsTo : component.getMapsTos()) {
          ComponentDefinition cd=getComponentDefinition(uriMap.get(component.getDefinitionURI()));
          if (cd != null) {
            String displayId=URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
            URI newURI=URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(),displayId,cd.getVersion());
            mapsTo.setRemote(newURI);
          }
        }
      }
      updateReferences(component,uriMap);
      for (      MapsTo mapsTo : component.getMapsTos()) {
        updateReferences(mapsTo,uriMap);
      }
    }
    for (    SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
      for (      Location loc : sa.getLocations()) {
        updateReferences(loc,uriMap);
      }
      updateReferences(sa,uriMap);
    }
    for (    SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
      updateReferences(sc,uriMap);
    }
    for (    URI sequenceURI : componentDefinition.getSequenceURIs()) {
      if (uriMap.get(sequenceURI) != null) {
        componentDefinition.removeSequence(sequenceURI);
        componentDefinition.addSequence(uriMap.get(sequenceURI));
      }
    }
  }
  for (  ModuleDefinition moduleDefinition : getModuleDefinitions()) {
    updateReferences(moduleDefinition,uriMap);
    for (    FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
      if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
        functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
        for (        MapsTo mapsTo : functionalComponent.getMapsTos()) {
          ComponentDefinition cd=getComponentDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
          if (cd != null) {
            String displayId=URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
            URI newURI=URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(),displayId,cd.getVersion());
            mapsTo.setRemote(newURI);
          }
        }
      }
      updateReferences(functionalComponent,uriMap);
      for (      MapsTo mapsTo : functionalComponent.getMapsTos()) {
        updateReferences(mapsTo,uriMap);
      }
    }
    for (    Module module : moduleDefinition.getModules()) {
      if (uriMap.get(module.getDefinitionURI()) != null) {
        module.setDefinition(uriMap.get(module.getDefinitionURI()));
        for (        MapsTo mapsTo : module.getMapsTos()) {
          ModuleDefinition md=getModuleDefinition(uriMap.get(module.getDefinitionURI()));
          if (md != null) {
            String displayId=URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
            URI newURI=URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(),displayId,md.getVersion());
            mapsTo.setRemote(newURI);
          }
        }
      }
      updateReferences(module,uriMap);
      for (      MapsTo mapsTo : module.getMapsTos()) {
        updateReferences(mapsTo,uriMap);
      }
    }
    for (    Interaction interaction : moduleDefinition.getInteractions()) {
      updateReferences(interaction,uriMap);
      for (      Participation participation : interaction.getParticipations()) {
        updateReferences(participation,uriMap);
      }
    }
    for (    URI modelURI : moduleDefinition.getModelURIs()) {
      if (uriMap.get(modelURI) != null) {
        moduleDefinition.removeModel(modelURI);
        moduleDefinition.addModel(uriMap.get(modelURI));
      }
    }
  }
  for (  Model model : getModels()) {
    updateReferences(model,uriMap);
  }
  for (  Sequence sequence : getSequences()) {
    updateReferences(sequence,uriMap);
  }
  for (  GenericTopLevel genericTopLevel : getGenericTopLevels()) {
    updateReferences(genericTopLevel,uriMap);
  }
}

Fixed version (ground truth):
private void updateReferences(HashMap<URI,URI> uriMap) throws SBOLValidationException {
  for (  Collection collection : getCollections()) {
    for (    URI memberURI : collection.getMemberURIs()) {
      if (uriMap.get(memberURI) != null) {
        collection.removeMember(memberURI);
        collection.addMember(uriMap.get(memberURI));
      }
    }
    updateReferences(collection,uriMap);
  }
  for (  ComponentDefinition componentDefinition : getComponentDefinitions()) {
    updateReferences(componentDefinition,uriMap);
    for (    Component component : componentDefinition.getComponents()) {
      if (uriMap.get(component.getDefinitionURI()) != null) {
        component.setDefinition(uriMap.get(component.getDefinitionURI()));
        for (        MapsTo mapsTo : component.getMapsTos()) {
          ComponentDefinition cd=getComponentDefinition(component.getDefinitionURI());
          if (cd != null) {
            String displayId=URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
            URI newURI=URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(),displayId,cd.getVersion());
            mapsTo.setRemote(newURI);
          }
        }
      }
      updateReferences(component,uriMap);
      for (      MapsTo mapsTo : component.getMapsTos()) {
        updateReferences(mapsTo,uriMap);
      }
    }
    for (    SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
      for (      Location loc : sa.getLocations()) {
        updateReferences(loc,uriMap);
      }
      updateReferences(sa,uriMap);
    }
    for (    SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
      updateReferences(sc,uriMap);
    }
    for (    URI sequenceURI : componentDefinition.getSequenceURIs()) {
      if (uriMap.get(sequenceURI) != null) {
        componentDefinition.removeSequence(sequenceURI);
        componentDefinition.addSequence(uriMap.get(sequenceURI));
      }
    }
  }
  for (  ModuleDefinition moduleDefinition : getModuleDefinitions()) {
    updateReferences(moduleDefinition,uriMap);
    for (    FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
      if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
        functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
        for (        MapsTo mapsTo : functionalComponent.getMapsTos()) {
          ComponentDefinition cd=getComponentDefinition(functionalComponent.getDefinitionURI());
          if (cd != null) {
            String displayId=URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
            URI newURI=URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(),displayId,cd.getVersion());
            mapsTo.setRemote(newURI);
          }
        }
      }
      updateReferences(functionalComponent,uriMap);
      for (      MapsTo mapsTo : functionalComponent.getMapsTos()) {
        updateReferences(mapsTo,uriMap);
      }
    }
    for (    Module module : moduleDefinition.getModules()) {
      if (uriMap.get(module.getDefinitionURI()) != null) {
        module.setDefinition(uriMap.get(module.getDefinitionURI()));
        for (        MapsTo mapsTo : module.getMapsTos()) {
          ModuleDefinition md=getModuleDefinition(module.getDefinitionURI());
          if (md != null) {
            String displayId=URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
            URI newURI=URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(),displayId,md.getVersion());
            mapsTo.setRemote(newURI);
          }
        }
      }
      updateReferences(module,uriMap);
      for (      MapsTo mapsTo : module.getMapsTos()) {
        updateReferences(mapsTo,uriMap);
      }
    }
    for (    Interaction interaction : moduleDefinition.getInteractions()) {
      updateReferences(interaction,uriMap);
      for (      Participation participation : interaction.getParticipations()) {
        updateReferences(participation,uriMap);
      }
    }
    for (    URI modelURI : moduleDefinition.getModelURIs()) {
      if (uriMap.get(modelURI) != null) {
        moduleDefinition.removeModel(modelURI);
        moduleDefinition.addModel(uriMap.get(modelURI));
      }
    }
  }
  for (  Model model : getModels()) {
    updateReferences(model,uriMap);
  }
  for (  Sequence sequence : getSequences()) {
    updateReferences(sequence,uriMap);
  }
  for (  GenericTopLevel genericTopLevel : getGenericTopLevels()) {
    updateReferences(genericTopLevel,uriMap);
  }
}