Program: 68212
Project: 68212
Buggy source:
private Object buildObjectValuesFromDOMRecord(DOMRecord record,AbstractSession session,ObjectBuildingQuery query,JoinedAttributeManager joinManager){
  Node root=record.getDOM();
  NodeList children=root.getChildNodes();
  ContainerPolicy cp=getContainerPolicy();
  Object container=cp.containerInstance();
  int length=children.getLength();
  for (int i=0; i < length; i++) {
    Object objectValue=null;
    org.w3c.dom.Node next=children.item(i);
    if (isUnmappedContent(next)) {
      if ((next.getNodeType() == Node.TEXT_NODE) && this.isMixedContent()) {
        if (next.getNodeValue().trim().length() > 0) {
          objectValue=next.getNodeValue();
          if (getConverter() != null) {
            objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
          }
          cp.addInto(objectValue,container,session);
        }
      }
 else       if (next.getNodeType() == Node.ELEMENT_NODE) {
        ClassDescriptor referenceDescriptor=null;
        DOMRecord nestedRecord=(DOMRecord)record.buildNestedRow((Element)next);
        if (!useXMLRoot) {
          referenceDescriptor=getDescriptor(nestedRecord,session,null);
          if ((referenceDescriptor != null) && (keepAsElementPolicy != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
            ObjectBuilder builder=referenceDescriptor.getObjectBuilder();
            objectValue=builder.buildObject(query,nestedRecord,joinManager);
            if (getConverter() != null) {
              objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
            }
            cp.addInto(objectValue,container,session);
          }
 else {
            if ((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
              XMLPlatformFactory.getInstance().getXMLPlatform().namespaceQualifyFragment((Element)next);
              objectValue=next;
              if (getConverter() != null) {
                objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
              }
              cp.addInto(objectValue,container,session);
            }
          }
        }
 else {
          String schemaType=((Element)next).getAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
          QName schemaTypeQName=null;
          XPathFragment frag=new XPathFragment();
          if ((null != schemaType) && (!schemaType.equals("String_Node_Str"))) {
            frag.setXPath(schemaType);
            if (frag.hasNamespace()) {
              String prefix=frag.getPrefix();
              XMLPlatform xmlPlatform=XMLPlatformFactory.getInstance().getXMLPlatform();
              String url=xmlPlatform.resolveNamespacePrefix(next,prefix);
              frag.setNamespaceURI(url);
              schemaTypeQName=new QName(url,frag.getLocalName());
            }
            XMLContext xmlContext=nestedRecord.getUnmarshaller().getXMLContext();
            referenceDescriptor=xmlContext.getDescriptorByGlobalType(frag);
          }
          if (referenceDescriptor == null) {
            try {
              QName qname=new QName(nestedRecord.getNamespaceURI(),nestedRecord.getLocalName());
              referenceDescriptor=getDescriptor(nestedRecord,session,qname);
            }
 catch (            XMLMarshalException e) {
              referenceDescriptor=null;
            }
            XMLDescriptor xmlReferenceDescriptor=(XMLDescriptor)referenceDescriptor;
            if (referenceDescriptor != null && xmlReferenceDescriptor.isWrapper()) {
              referenceDescriptor=null;
            }
          }
          if ((referenceDescriptor != null) && (getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
            ObjectBuilder builder=referenceDescriptor.getObjectBuilder();
            objectValue=builder.buildObject(query,nestedRecord,joinManager);
            Object updated=((XMLDescriptor)referenceDescriptor).wrapObjectInXMLRoot(objectValue,next.getNamespaceURI(),next.getLocalName(),next.getPrefix(),false);
            if (getConverter() != null) {
              updated=getConverter().convertDataValueToObjectValue(updated,session,record.getUnmarshaller());
            }
            cp.addInto(updated,container,session);
          }
 else           if ((referenceDescriptor == null) && (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT)) {
            XMLPlatformFactory.getInstance().getXMLPlatform().namespaceQualifyFragment((Element)next);
            objectValue=next;
            if (getConverter() != null) {
              objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
            }
            cp.addInto(objectValue,container,session);
          }
 else {
            Object value=null;
            Node textchild=((Element)next).getFirstChild();
            if ((textchild != null) && (textchild.getNodeType() == Node.TEXT_NODE)) {
              value=((Text)textchild).getNodeValue();
            }
            if ((value != null) && !value.equals("String_Node_Str")) {
              if (schemaTypeQName != null) {
                Class theClass=(Class)XMLConversionManager.getDefaultXMLTypes().get(schemaTypeQName);
                if (theClass != null) {
                  value=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(value,theClass,schemaTypeQName);
                }
              }
              if (getConverter() != null) {
                value=getConverter().convertDataValueToObjectValue(value,session,record.getUnmarshaller());
              }
              XMLRoot rootValue=new XMLRoot();
              rootValue.setLocalName(next.getLocalName());
              rootValue.setSchemaType(schemaTypeQName);
              rootValue.setNamespaceURI(next.getNamespaceURI());
              rootValue.setObject(value);
              cp.addInto(rootValue,container,session);
            }
          }
        }
      }
    }
  }
  return container;
}

Fixed version (ground truth):
private Object buildObjectValuesFromDOMRecord(DOMRecord record,AbstractSession session,ObjectBuildingQuery query,JoinedAttributeManager joinManager){
  Node root=record.getDOM();
  NodeList children=root.getChildNodes();
  ContainerPolicy cp=getContainerPolicy();
  Object container=cp.containerInstance();
  int length=children.getLength();
  Node next=null;
  if (length > 0) {
    next=record.getDOM().getFirstChild();
  }
  while (next != null) {
    Object objectValue=null;
    if (isUnmappedContent(next)) {
      if ((next.getNodeType() == Node.TEXT_NODE) && this.isMixedContent()) {
        if (next.getNodeValue().trim().length() > 0) {
          objectValue=next.getNodeValue();
          if (getConverter() != null) {
            objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
          }
          cp.addInto(objectValue,container,session);
        }
      }
 else       if (next.getNodeType() == Node.ELEMENT_NODE) {
        ClassDescriptor referenceDescriptor=null;
        DOMRecord nestedRecord=(DOMRecord)record.buildNestedRow((Element)next);
        if (!useXMLRoot) {
          referenceDescriptor=getDescriptor(nestedRecord,session,null);
          if ((referenceDescriptor != null) && (keepAsElementPolicy != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
            ObjectBuilder builder=referenceDescriptor.getObjectBuilder();
            objectValue=builder.buildObject(query,nestedRecord,joinManager);
            if (getConverter() != null) {
              objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
            }
            cp.addInto(objectValue,container,session);
          }
 else {
            if ((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
              XMLPlatformFactory.getInstance().getXMLPlatform().namespaceQualifyFragment((Element)next);
              objectValue=next;
              if (getConverter() != null) {
                objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
              }
              cp.addInto(objectValue,container,session);
            }
          }
        }
 else {
          String schemaType=((Element)next).getAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
          QName schemaTypeQName=null;
          XPathFragment frag=new XPathFragment();
          if ((null != schemaType) && (!schemaType.equals("String_Node_Str"))) {
            frag.setXPath(schemaType);
            if (frag.hasNamespace()) {
              String prefix=frag.getPrefix();
              XMLPlatform xmlPlatform=XMLPlatformFactory.getInstance().getXMLPlatform();
              String url=xmlPlatform.resolveNamespacePrefix(next,prefix);
              frag.setNamespaceURI(url);
              schemaTypeQName=new QName(url,frag.getLocalName());
            }
            XMLContext xmlContext=nestedRecord.getUnmarshaller().getXMLContext();
            referenceDescriptor=xmlContext.getDescriptorByGlobalType(frag);
          }
          if (referenceDescriptor == null) {
            try {
              QName qname=new QName(nestedRecord.getNamespaceURI(),nestedRecord.getLocalName());
              referenceDescriptor=getDescriptor(nestedRecord,session,qname);
            }
 catch (            XMLMarshalException e) {
              referenceDescriptor=null;
            }
            XMLDescriptor xmlReferenceDescriptor=(XMLDescriptor)referenceDescriptor;
            if (referenceDescriptor != null && xmlReferenceDescriptor.isWrapper()) {
              referenceDescriptor=null;
            }
          }
          if ((referenceDescriptor != null) && (getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
            ObjectBuilder builder=referenceDescriptor.getObjectBuilder();
            objectValue=builder.buildObject(query,nestedRecord,joinManager);
            Object updated=((XMLDescriptor)referenceDescriptor).wrapObjectInXMLRoot(objectValue,next.getNamespaceURI(),next.getLocalName(),next.getPrefix(),false);
            if (getConverter() != null) {
              updated=getConverter().convertDataValueToObjectValue(updated,session,record.getUnmarshaller());
            }
            cp.addInto(updated,container,session);
          }
 else           if ((referenceDescriptor == null) && (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT)) {
            XMLPlatformFactory.getInstance().getXMLPlatform().namespaceQualifyFragment((Element)next);
            objectValue=next;
            if (getConverter() != null) {
              objectValue=getConverter().convertDataValueToObjectValue(objectValue,session,record.getUnmarshaller());
            }
            cp.addInto(objectValue,container,session);
          }
 else {
            Object value=null;
            Node textchild=((Element)next).getFirstChild();
            if ((textchild != null) && (textchild.getNodeType() == Node.TEXT_NODE)) {
              value=((Text)textchild).getNodeValue();
            }
            if ((value != null) && !value.equals("String_Node_Str")) {
              if (schemaTypeQName != null) {
                Class theClass=(Class)XMLConversionManager.getDefaultXMLTypes().get(schemaTypeQName);
                if (theClass != null) {
                  value=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(value,theClass,schemaTypeQName);
                }
              }
              if (getConverter() != null) {
                value=getConverter().convertDataValueToObjectValue(value,session,record.getUnmarshaller());
              }
              XMLRoot rootValue=new XMLRoot();
              rootValue.setLocalName(next.getLocalName());
              rootValue.setSchemaType(schemaTypeQName);
              rootValue.setNamespaceURI(next.getNamespaceURI());
              rootValue.setObject(value);
              cp.addInto(rootValue,container,session);
            }
          }
        }
      }
    }
    next=next.getNextSibling();
  }
  return container;
}