Program: 65678
Project: 65678
Buggy source:
/** 
 * INTERNAL: Override the parent's buildObject to allow for the caching of aggregate objects in OX. By caching aggregates along with XML Nodes that they were created from, we are able to preserve the structure and unmapped content of the document that was used to create these objects.
 */
@Override public Object buildObject(ObjectBuildingQuery query,AbstractRecord databaseRow,JoinedAttributeManager joinManager) throws DatabaseException, QueryException {
  XMLRecord row=(XMLRecord)databaseRow;
  row.setSession(query.getSession());
  XMLUnmarshaller unmarshaller=row.getUnmarshaller();
  Object parent=row.getOwningObject();
  Object pk=extractPrimaryKeyFromRow(databaseRow,query.getSession());
  if (!(isXmlDescriptor() || getDescriptor().isDescriptorTypeAggregate())) {
    return super.buildObject(query,databaseRow,joinManager);
  }
  query.getSession().startOperationProfile(SessionProfiler.ObjectBuilding,query,SessionProfiler.ALL);
  ClassDescriptor concreteDescriptor=getDescriptor();
  Object domainObject=null;
  if (concreteDescriptor.hasInheritance() && (parent == null)) {
    Class classValue=concreteDescriptor.getInheritancePolicy().classFromRow(databaseRow,query.getSession());
    if ((classValue == null) && isXmlDescriptor()) {
      QName leafElementType=((XMLDescriptor)concreteDescriptor).getDefaultRootElementType();
      if (leafElementType != null) {
        Object indicator=concreteDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
        if (indicator != null) {
          classValue=(Class)indicator;
        }
      }
    }
    if (classValue != null) {
      concreteDescriptor=query.getSession().getDescriptor(classValue);
      if ((concreteDescriptor == null) && query.hasPartialAttributeExpressions()) {
        concreteDescriptor=getDescriptor();
      }
      if (concreteDescriptor == null) {
        throw QueryException.noDescriptorForClassFromInheritancePolicy(query,classValue);
      }
    }
 else {
      if (Modifier.isAbstract(concreteDescriptor.getJavaClass().getModifiers())) {
        throw DescriptorException.missingClassIndicatorField(databaseRow,concreteDescriptor.getInheritancePolicy().getDescriptor());
      }
    }
  }
  domainObject=concreteDescriptor.getObjectBuilder().buildNewInstance();
  row.setCurrentObject(domainObject);
  if ((unmarshaller != null) && (unmarshaller.getUnmarshalListener() != null)) {
    unmarshaller.getUnmarshalListener().beforeUnmarshal(domainObject,parent);
  }
  concreteDescriptor.getObjectBuilder().buildAttributesIntoObject(domainObject,null,databaseRow,query,joinManager,false,query.getSession());
  if (isXmlDescriptor() && ((XMLDescriptor)concreteDescriptor).getPrimaryKeyFieldNames().size() > 0) {
    if ((pk == null) || (((CacheId)pk).getPrimaryKey().length == 0)) {
      pk=new CacheId(new Object[]{new WeakObjectWrapper(domainObject)});
    }
    CacheKey key=query.getSession().getIdentityMapAccessorInstance().acquireDeferredLock(pk,concreteDescriptor.getJavaClass(),concreteDescriptor);
    if (((XMLDescriptor)concreteDescriptor).shouldPreserveDocument()) {
      key.setRecord(databaseRow);
    }
    key.setObject(domainObject);
    key.releaseDeferredLock();
  }
  DocumentPreservationPolicy docPresPolicy=((DOMRecord)row).getDocPresPolicy();
  if (docPresPolicy != null) {
    ((DOMRecord)row).getDocPresPolicy().addObjectToCache(domainObject,((DOMRecord)row).getDOM());
  }
  query.getSession().endOperationProfile(SessionProfiler.ObjectBuilding,query,SessionProfiler.ALL);
  if ((unmarshaller != null) && (unmarshaller.getUnmarshalListener() != null)) {
    unmarshaller.getUnmarshalListener().afterUnmarshal(domainObject,parent);
  }
  return domainObject;
}

Fixed version (ground truth):
/** 
 * INTERNAL: Override the parent's buildObject to allow for the caching of aggregate objects in OX. By caching aggregates along with XML Nodes that they were created from, we are able to preserve the structure and unmapped content of the document that was used to create these objects.
 */
@Override public Object buildObject(ObjectBuildingQuery query,AbstractRecord databaseRow,JoinedAttributeManager joinManager) throws DatabaseException, QueryException {
  XMLRecord row=(XMLRecord)databaseRow;
  row.setSession(query.getSession());
  XMLUnmarshaller unmarshaller=row.getUnmarshaller();
  Object parent=row.getOwningObject();
  Object pk=extractPrimaryKeyFromRow(databaseRow,query.getSession());
  if (!(isXmlDescriptor() || getDescriptor().isDescriptorTypeAggregate())) {
    return super.buildObject(query,databaseRow,joinManager);
  }
  query.getSession().startOperationProfile(SessionProfiler.ObjectBuilding,query,SessionProfiler.ALL);
  ClassDescriptor concreteDescriptor=getDescriptor();
  Object domainObject=null;
  if (concreteDescriptor.hasInheritance() && (parent == null)) {
    Class classValue=concreteDescriptor.getInheritancePolicy().classFromRow(databaseRow,query.getSession());
    if ((classValue == null) && isXmlDescriptor()) {
      QName leafElementType=((XMLDescriptor)concreteDescriptor).getDefaultRootElementType();
      if (leafElementType != null) {
        XPathQName xpathQName=new XPathQName(leafElementType,row.isNamespaceAware());
        Object indicator=concreteDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(xpathQName);
        if (indicator != null) {
          classValue=(Class)indicator;
        }
      }
    }
    if (classValue != null) {
      concreteDescriptor=query.getSession().getDescriptor(classValue);
      if ((concreteDescriptor == null) && query.hasPartialAttributeExpressions()) {
        concreteDescriptor=getDescriptor();
      }
      if (concreteDescriptor == null) {
        throw QueryException.noDescriptorForClassFromInheritancePolicy(query,classValue);
      }
    }
 else {
      if (Modifier.isAbstract(concreteDescriptor.getJavaClass().getModifiers())) {
        throw DescriptorException.missingClassIndicatorField(databaseRow,concreteDescriptor.getInheritancePolicy().getDescriptor());
      }
    }
  }
  domainObject=concreteDescriptor.getObjectBuilder().buildNewInstance();
  row.setCurrentObject(domainObject);
  if ((unmarshaller != null) && (unmarshaller.getUnmarshalListener() != null)) {
    unmarshaller.getUnmarshalListener().beforeUnmarshal(domainObject,parent);
  }
  concreteDescriptor.getObjectBuilder().buildAttributesIntoObject(domainObject,null,databaseRow,query,joinManager,false,query.getSession());
  if (isXmlDescriptor() && ((XMLDescriptor)concreteDescriptor).getPrimaryKeyFieldNames().size() > 0) {
    if ((pk == null) || (((CacheId)pk).getPrimaryKey().length == 0)) {
      pk=new CacheId(new Object[]{new WeakObjectWrapper(domainObject)});
    }
    CacheKey key=query.getSession().getIdentityMapAccessorInstance().acquireDeferredLock(pk,concreteDescriptor.getJavaClass(),concreteDescriptor);
    if (((XMLDescriptor)concreteDescriptor).shouldPreserveDocument()) {
      key.setRecord(databaseRow);
    }
    key.setObject(domainObject);
    key.releaseDeferredLock();
  }
  DocumentPreservationPolicy docPresPolicy=((DOMRecord)row).getDocPresPolicy();
  if (docPresPolicy != null) {
    ((DOMRecord)row).getDocPresPolicy().addObjectToCache(domainObject,((DOMRecord)row).getDOM());
  }
  query.getSession().endOperationProfile(SessionProfiler.ObjectBuilding,query,SessionProfiler.ALL);
  if ((unmarshaller != null) && (unmarshaller.getUnmarshalListener() != null)) {
    unmarshaller.getUnmarshalListener().afterUnmarshal(domainObject,parent);
  }
  return domainObject;
}