Program: 12376
Project: 12376
Buggy source:
/** 
 * @param SBOLDoc
 * @param topLevel
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:<ul> <li>any of the following SBOL validation rules was violated:  10202, 10203, 10204, 10206, 10208, 10212, 10213, 12102; or</li> <li>an SBOL validation rule violation occurred in the following constructor or methods: <ul> <li> {@link GenericTopLevel#GenericTopLevel(URI,QName)}, </li> <li>  {@link GenericTopLevel#setDisplayId(String)}, </li> <li>  {@link GenericTopLevel#setVersion(String)}, </li> <li>  {@link GenericTopLevel#setWasDerivedFrom(URI)}, </li> <li>  {@link Identified#setAnnotations(List)}, or</li> <li>  {@link SBOLDocument#addGenericTopLevel(GenericTopLevel)}.</li> </ul> </li> </ul>
 */
@SuppressWarnings("String_Node_Str") private static GenericTopLevel parseGenericTopLevel(SBOLDocument SBOLDoc,IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
  String displayId=null;
  String name=null;
  String description=null;
  URI persistentIdentity=null;
  String version=null;
  Set<URI> wasDerivedFroms=new HashSet<>();
  Set<URI> wasGeneratedBys=new HashSet<>();
  Set<URI> attachments=new HashSet<>();
  QName type=topLevel.getType();
  List<Annotation> annotations=new ArrayList<>();
  for (  NamedProperty<QName> namedProperty : topLevel.getProperties()) {
    if (namedProperty.getName().equals(Sbol2Terms.Description.type)) {
      String typeStr=((Literal<QName>)namedProperty.getValue()).getValue().toString();
      String nameSpace=URIcompliance.extractNamespace(URI.create(typeStr));
      String localPart=URIcompliance.extractDisplayId(URI.create(typeStr));
      String prefix=null;
      if (nameSpace == null) {
        if (typeStr.lastIndexOf('/') > typeStr.lastIndexOf('#')) {
          if (typeStr.lastIndexOf('/') > typeStr.lastIndexOf(':')) {
            nameSpace=typeStr.substring(0,typeStr.lastIndexOf('/') + 1);
            localPart=typeStr.substring(typeStr.lastIndexOf('/') + 1);
          }
 else {
            nameSpace=typeStr.substring(0,typeStr.lastIndexOf(':') + 1);
            localPart=typeStr.substring(typeStr.lastIndexOf(':') + 1);
          }
        }
 else         if (typeStr.lastIndexOf('#') > typeStr.lastIndexOf(':')) {
          nameSpace=typeStr.substring(0,typeStr.lastIndexOf('#') + 1);
          localPart=typeStr.substring(typeStr.lastIndexOf('#') + 1);
        }
 else {
          nameSpace=typeStr.substring(0,typeStr.lastIndexOf(':') + 1);
          localPart=typeStr.substring(typeStr.lastIndexOf(':') + 1);
        }
        prefix=SBOLDoc.getNamespacePrefix(URI.create(nameSpace));
        if (prefix == null) {
          prefix="String_Node_Str";
          int prefixCnt=0;
          while (SBOLDoc.getNamespace(prefix) != null) {
            prefixCnt++;
            prefix="String_Node_Str" + prefixCnt;
          }
          SBOLDoc.addNamespace(new QName(nameSpace,localPart,prefix));
        }
      }
 else {
        prefix=SBOLDoc.getNamespacePrefix(URI.create(nameSpace));
      }
      if (!nameSpace.equals(Sbol2Terms.sbol2.getNamespaceURI()))       type=new QName(nameSpace,localPart,prefix);
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
      if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      persistentIdentity=URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString());
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
      if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      version=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
      if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      displayId=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
      if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      name=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
      if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      description=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
      if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      wasDerivedFroms.add(URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString()));
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
      if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      wasGeneratedBys.add(URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString()));
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
      if (namedProperty.getValue() instanceof Literal) {
        if (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI)) {
          throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
        }
        attachments.add(URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString()));
      }
 else       if (namedProperty.getValue() instanceof IdentifiableDocument) {
        if (((IdentifiableDocument<QName>)namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
          Attachment attachment=parseAttachment(SBOLDoc,(IdentifiableDocument<QName>)namedProperty.getValue());
          attachments.add(attachment.getIdentity());
        }
 else {
          throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
        }
      }
 else {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
    }
 else {
      annotations.add(new Annotation(namedProperty));
    }
  }
  GenericTopLevel t=new GenericTopLevel(topLevel.getIdentity(),type);
  if (persistentIdentity != null)   t.setPersistentIdentity(persistentIdentity);
  if (version != null)   t.setVersion(version);
  if (displayId != null)   t.setDisplayId(displayId);
  if (name != null)   t.setName(name);
  if (description != null)   t.setDescription(description);
  t.setWasDerivedFroms(wasDerivedFroms);
  t.setWasGeneratedBys(wasGeneratedBys);
  if (!annotations.isEmpty())   t.setAnnotations(annotations);
  GenericTopLevel oldG=SBOLDoc.getGenericTopLevel(topLevel.getIdentity());
  if (oldG == null) {
    SBOLDoc.addGenericTopLevel(t);
  }
 else {
    if (!t.equals(oldG)) {
      throw new SBOLValidationException("String_Node_Str",t);
    }
  }
  return t;
}

Fixed version (ground truth):
/** 
 * @param SBOLDoc
 * @param topLevel
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:<ul> <li>any of the following SBOL validation rules was violated:  10202, 10203, 10204, 10206, 10208, 10212, 10213, 12102; or</li> <li>an SBOL validation rule violation occurred in the following constructor or methods: <ul> <li> {@link GenericTopLevel#GenericTopLevel(URI,QName)}, </li> <li>  {@link GenericTopLevel#setDisplayId(String)}, </li> <li>  {@link GenericTopLevel#setVersion(String)}, </li> <li>  {@link GenericTopLevel#setWasDerivedFrom(URI)}, </li> <li>  {@link Identified#setAnnotations(List)}, or</li> <li>  {@link SBOLDocument#addGenericTopLevel(GenericTopLevel)}.</li> </ul> </li> </ul>
 */
@SuppressWarnings("String_Node_Str") private static GenericTopLevel parseGenericTopLevel(SBOLDocument SBOLDoc,IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
  String displayId=null;
  String name=null;
  String description=null;
  URI persistentIdentity=null;
  String version=null;
  Set<URI> wasDerivedFroms=new HashSet<>();
  Set<URI> wasGeneratedBys=new HashSet<>();
  Set<URI> attachments=new HashSet<>();
  QName type=topLevel.getType();
  List<Annotation> annotations=new ArrayList<>();
  for (  NamedProperty<QName> namedProperty : topLevel.getProperties()) {
    if (namedProperty.getName().equals(Sbol2Terms.Description.type)) {
      String typeStr=((Literal<QName>)namedProperty.getValue()).getValue().toString();
      String nameSpace=URIcompliance.extractNamespace(URI.create(typeStr));
      String localPart=URIcompliance.extractDisplayId(URI.create(typeStr));
      String prefix=null;
      if (nameSpace == null) {
        if (typeStr.lastIndexOf('/') > typeStr.lastIndexOf('#')) {
          if (typeStr.lastIndexOf('/') > typeStr.lastIndexOf(':')) {
            nameSpace=typeStr.substring(0,typeStr.lastIndexOf('/') + 1);
            localPart=typeStr.substring(typeStr.lastIndexOf('/') + 1);
          }
 else {
            nameSpace=typeStr.substring(0,typeStr.lastIndexOf(':') + 1);
            localPart=typeStr.substring(typeStr.lastIndexOf(':') + 1);
          }
        }
 else         if (typeStr.lastIndexOf('#') > typeStr.lastIndexOf(':')) {
          nameSpace=typeStr.substring(0,typeStr.lastIndexOf('#') + 1);
          localPart=typeStr.substring(typeStr.lastIndexOf('#') + 1);
        }
 else {
          nameSpace=typeStr.substring(0,typeStr.lastIndexOf(':') + 1);
          localPart=typeStr.substring(typeStr.lastIndexOf(':') + 1);
        }
        prefix=SBOLDoc.getNamespacePrefix(URI.create(nameSpace));
        if (prefix == null) {
          prefix="String_Node_Str";
          int prefixCnt=0;
          while (SBOLDoc.getNamespace(prefix) != null) {
            prefixCnt++;
            prefix="String_Node_Str" + prefixCnt;
          }
          SBOLDoc.addNamespace(new QName(nameSpace,localPart,prefix));
        }
      }
 else {
        prefix=SBOLDoc.getNamespacePrefix(URI.create(nameSpace));
      }
      if (!nameSpace.equals(Sbol2Terms.sbol2.getNamespaceURI()))       type=new QName(nameSpace,localPart,prefix);
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
      if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      persistentIdentity=URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString());
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
      if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      version=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
      if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      displayId=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
      if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      name=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
      if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof String))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      description=((Literal<QName>)namedProperty.getValue()).getValue().toString();
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
      if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      wasDerivedFroms.add(URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString()));
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
      if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI))) {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
      wasGeneratedBys.add(URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString()));
    }
 else     if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
      if (namedProperty.getValue() instanceof Literal) {
        if (!(((Literal<QName>)namedProperty.getValue()).getValue() instanceof URI)) {
          throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
        }
        attachments.add(URI.create(((Literal<QName>)namedProperty.getValue()).getValue().toString()));
      }
 else       if (namedProperty.getValue() instanceof IdentifiableDocument) {
        if (((IdentifiableDocument<QName>)namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
          Attachment attachment=parseAttachment(SBOLDoc,(IdentifiableDocument<QName>)namedProperty.getValue());
          attachments.add(attachment.getIdentity());
        }
 else {
          throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
        }
      }
 else {
        throw new SBOLValidationException("String_Node_Str",topLevel.getIdentity());
      }
    }
 else {
      annotations.add(new Annotation(namedProperty));
    }
  }
  GenericTopLevel t=new GenericTopLevel(topLevel.getIdentity(),type);
  if (persistentIdentity != null)   t.setPersistentIdentity(persistentIdentity);
  if (version != null)   t.setVersion(version);
  if (displayId != null)   t.setDisplayId(displayId);
  if (name != null)   t.setName(name);
  if (description != null)   t.setDescription(description);
  t.setWasDerivedFroms(wasDerivedFroms);
  t.setWasGeneratedBys(wasGeneratedBys);
  t.setAttachments(attachments);
  if (!annotations.isEmpty())   t.setAnnotations(annotations);
  GenericTopLevel oldG=SBOLDoc.getGenericTopLevel(topLevel.getIdentity());
  if (oldG == null) {
    SBOLDoc.addGenericTopLevel(t);
  }
 else {
    if (!t.equals(oldG)) {
      throw new SBOLValidationException("String_Node_Str",t);
    }
  }
  return t;
}