Program: 66079
Project: 66079
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=null;
  if (reuseContainer) {
    Object currentObject=record.getCurrentObject();
    Object value=getAttributeAccessor().getAttributeValueFromObject(currentObject);
    container=value != null ? value : cp.containerInstance();
  }
 else {
    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);
          objectValue=buildObjectForNonXMLRoot(referenceDescriptor,getConverter(),query,record,nestedRecord,joinManager,session,next,container,cp);
        }
 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.length() > 0)) {
            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)) {
            buildObjectAndWrapInXMLRoot(referenceDescriptor,getConverter(),query,record,nestedRecord,joinManager,session,next,container,cp);
          }
 else           if ((referenceDescriptor == null) && (getKeepAsElementPolicy() == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT)) {
            buildObjectNoReferenceDescriptor(record,session,next,container,cp);
          }
 else {
            Node textchild=((Element)next).getFirstChild();
            if ((textchild != null) && (textchild.getNodeType() == Node.TEXT_NODE)) {
              String stringValue=((Text)textchild).getNodeValue();
              if ((stringValue != null) && stringValue.length() > 0) {
                Object convertedValue=stringValue;
                if (schemaTypeQName != null) {
                  Class theClass=(Class)XMLConversionManager.getDefaultXMLTypes().get(schemaTypeQName);
                  if (theClass != null) {
                    convertedValue=((XMLConversionManager)session.getDatasourcePlatform().getConversionManager()).convertObject(convertedValue,theClass,schemaTypeQName);
                  }
                }
                if (getConverter() != null) {
                  convertedValue=getConverter().convertDataValueToObjectValue(convertedValue,session,record.getUnmarshaller());
                }
                XMLRoot rootValue=new XMLRoot();
                rootValue.setLocalName(next.getLocalName());
                rootValue.setSchemaType(schemaTypeQName);
                rootValue.setNamespaceURI(next.getNamespaceURI());
                rootValue.setObject(convertedValue);
                cp.addInto(rootValue,container,session);
              }
            }
          }
        }
      }
    }
    next=next.getNextSibling();
  }
  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=null;
  if (reuseContainer) {
    Object currentObject=record.getCurrentObject();
    Object value=getAttributeAccessor().getAttributeValueFromObject(currentObject);
    container=value != null ? value : cp.containerInstance();
  }
 else {
    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);
          objectValue=buildObjectForNonXMLRoot(referenceDescriptor,getConverter(),query,record,nestedRecord,joinManager,session,next,container,cp);
        }
 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.length() > 0)) {
            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 (getKeepAsElementPolicy() == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT || (referenceDescriptor == null && getKeepAsElementPolicy() == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT)) {
            Object objVal=buildObjectNoReferenceDescriptor(record,getConverter(),session,next,null,null);
            if (referenceDescriptor != null) {
              objVal=((XMLDescriptor)referenceDescriptor).wrapObjectInXMLRoot(objVal,next.getNamespaceURI(),next.getLocalName(),next.getPrefix(),false);
              cp.addInto(objVal,container,session);
            }
 else {
              cp.addInto(buildXMLRoot(next,objVal),container,session);
            }
          }
 else           if (referenceDescriptor != null) {
            buildObjectAndWrapInXMLRoot(referenceDescriptor,getConverter(),query,record,nestedRecord,joinManager,session,next,container,cp);
          }
 else {
            XMLRoot rootValue;
            if ((rootValue=buildXMLRootForText(next,schemaTypeQName,getConverter(),session,record)) != null) {
              cp.addInto(rootValue,container,session);
            }
          }
        }
      }
    }
    next=next.getNextSibling();
  }
  return container;
}