Program: 12593
Project: 12593
Buggy source:
@SafeVarargs private final <TL extends TopLevel>void addTopLevel(TL newTopLevel,Map<URI,TL> instancesMap,String typeName,Map<URI,? extends Identified>... maps) throws SBOLValidationException {
  if (compliant && newTopLevel.checkDescendantsURIcompliance()) {
    URI persistentId=URI.create(extractPersistentId(newTopLevel.getIdentity()));
    if (keyExistsInAnyMap(persistentId,maps))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    if (instancesMap.containsKey(newTopLevel.getIdentity()))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    String prefix=extractURIprefix(persistentId);
    while (prefix != null) {
      if (keyExistsInAnyMap(URI.create(prefix),maps))       throw new SBOLValidationException("String_Node_Str",newTopLevel);
      if (instancesMap.containsKey(URI.create(prefix)))       throw new SBOLValidationException("String_Node_Str",newTopLevel);
      prefix=extractURIprefix(URI.create(prefix));
    }
    if (prefixes.contains(persistentId.toString())) {
      throw new SBOLValidationException("String_Node_Str" + persistentId.toString() + "String_Node_Str");
    }
    prefix=extractURIprefix(persistentId);
    while (prefix != null) {
      prefixes.add(prefix);
      prefix=extractURIprefix(URI.create(prefix));
    }
    instancesMap.put(newTopLevel.getIdentity(),newTopLevel);
    Identified latest=instancesMap.get(persistentId);
    if (latest == null) {
      instancesMap.put(persistentId,newTopLevel);
    }
 else {
      if (isFirstVersionNewer(extractVersion(newTopLevel.getIdentity()),extractVersion(latest.getIdentity()))) {
        instancesMap.put(persistentId,newTopLevel);
      }
    }
  }
 else {
    if (keyExistsInAnyMap(newTopLevel.getIdentity()))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    if (instancesMap.containsKey(newTopLevel.getIdentity()))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    instancesMap.put(newTopLevel.getIdentity(),newTopLevel);
    if (newTopLevel.isSetPersistentIdentity()) {
      Identified latest=instancesMap.get(newTopLevel.getPersistentIdentity());
      if (latest == null) {
        instancesMap.put(newTopLevel.getPersistentIdentity(),newTopLevel);
      }
 else {
        if (isFirstVersionNewer(extractVersion(newTopLevel.getIdentity()),extractVersion(latest.getIdentity()))) {
          instancesMap.put(newTopLevel.getPersistentIdentity(),newTopLevel);
        }
      }
    }
  }
  newTopLevel.setSBOLDocument(this);
}

Fixed version (ground truth):
@SafeVarargs private final <TL extends TopLevel>void addTopLevel(TL newTopLevel,Map<URI,TL> instancesMap,String typeName,Map<URI,? extends Identified>... maps) throws SBOLValidationException {
  boolean childrenCompliant=true;
  try {
    newTopLevel.checkDescendantsURIcompliance();
  }
 catch (  SBOLValidationException e) {
    childrenCompliant=false;
  }
  if (compliant && childrenCompliant) {
    URI persistentId=URI.create(extractPersistentId(newTopLevel.getIdentity()));
    if (keyExistsInAnyMap(persistentId,maps))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    if (instancesMap.containsKey(newTopLevel.getIdentity()))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    String prefix=extractURIprefix(persistentId);
    while (prefix != null) {
      if (keyExistsInAnyMap(URI.create(prefix),maps))       throw new SBOLValidationException("String_Node_Str",newTopLevel);
      if (instancesMap.containsKey(URI.create(prefix)))       throw new SBOLValidationException("String_Node_Str",newTopLevel);
      prefix=extractURIprefix(URI.create(prefix));
    }
    if (prefixes.contains(persistentId.toString())) {
      throw new SBOLValidationException("String_Node_Str" + persistentId.toString() + "String_Node_Str");
    }
    prefix=extractURIprefix(persistentId);
    while (prefix != null) {
      prefixes.add(prefix);
      prefix=extractURIprefix(URI.create(prefix));
    }
    instancesMap.put(newTopLevel.getIdentity(),newTopLevel);
    Identified latest=instancesMap.get(persistentId);
    if (latest == null) {
      instancesMap.put(persistentId,newTopLevel);
    }
 else {
      if (isFirstVersionNewer(extractVersion(newTopLevel.getIdentity()),extractVersion(latest.getIdentity()))) {
        instancesMap.put(persistentId,newTopLevel);
      }
    }
  }
 else {
    if (keyExistsInAnyMap(newTopLevel.getIdentity()))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    if (instancesMap.containsKey(newTopLevel.getIdentity()))     throw new SBOLValidationException("String_Node_Str",newTopLevel);
    instancesMap.put(newTopLevel.getIdentity(),newTopLevel);
    if (newTopLevel.isSetPersistentIdentity()) {
      Identified latest=instancesMap.get(newTopLevel.getPersistentIdentity());
      if (latest == null) {
        instancesMap.put(newTopLevel.getPersistentIdentity(),newTopLevel);
      }
 else {
        if (isFirstVersionNewer(extractVersion(newTopLevel.getIdentity()),extractVersion(latest.getIdentity()))) {
          instancesMap.put(newTopLevel.getPersistentIdentity(),newTopLevel);
        }
      }
    }
  }
  newTopLevel.setSBOLDocument(this);
}