Program: 12397
Project: 12397
Buggy source:
private void updateReferences(HashMap<URI,URI> uriMap) throws SBOLValidationException {
  for (  TopLevel topLevel : getTopLevels()) {
    for (    URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
      if (uriMap.get(wasDerivedFrom) != null) {
        topLevel.removeWasDerivedFrom(wasDerivedFrom);
        topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
      }
    }
    for (    URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
      if (uriMap.get(wasGeneratedBy) != null) {
        topLevel.removeWasGeneratedBy(wasGeneratedBy);
        topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
      }
    }
  }
  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);
  }
  for (  Activity activity : getActivities()) {
    updateReferences(activity,uriMap);
    for (    Association association : activity.getAssociations()) {
      if (uriMap.get(association.getAgentURI()) != null) {
        association.setAgent(uriMap.get(association.getAgentURI()));
      }
      if (uriMap.get(association.getPlanURI()) != null) {
        association.setPlan(uriMap.get(association.getPlanURI()));
      }
      updateReferences(association,uriMap);
    }
    for (    Usage usage : activity.getUsages()) {
      if (uriMap.get(usage.getEntityURI()) != null) {
        usage.setEntity(uriMap.get(usage.getEntity()));
      }
      updateReferences(usage,uriMap);
    }
  }
  for (  Agent agent : getAgents()) {
    updateReferences(agent,uriMap);
  }
  for (  Plan plan : getPlans()) {
    updateReferences(plan,uriMap);
  }
}

Fixed version (ground truth):
private void updateReferences(HashMap<URI,URI> uriMap) throws SBOLValidationException {
  for (  TopLevel topLevel : getTopLevels()) {
    for (    URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
      if (uriMap.get(wasDerivedFrom) != null) {
        topLevel.removeWasDerivedFrom(wasDerivedFrom);
        topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
      }
    }
    for (    URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
      if (uriMap.get(wasGeneratedBy) != null) {
        topLevel.removeWasGeneratedBy(wasGeneratedBy);
        topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
      }
    }
  }
  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);
  }
  for (  Activity activity : getActivities()) {
    updateReferences(activity,uriMap);
    for (    Association association : activity.getAssociations()) {
      if (uriMap.get(association.getAgentURI()) != null) {
        association.setAgent(uriMap.get(association.getAgentURI()));
      }
      if (uriMap.get(association.getPlanURI()) != null) {
        association.setPlan(uriMap.get(association.getPlanURI()));
      }
      updateReferences(association,uriMap);
    }
    for (    Usage usage : activity.getUsages()) {
      if (uriMap.get(usage.getEntityURI()) != null) {
        usage.setEntity(uriMap.get(usage.getEntityURI()));
      }
      updateReferences(usage,uriMap);
    }
  }
  for (  Agent agent : getAgents()) {
    updateReferences(agent,uriMap);
  }
  for (  Plan plan : getPlans()) {
    updateReferences(plan,uriMap);
  }
}