Program: 66766
Project: 66766
Buggy source:
/** 
 * ADVANCED: Adjust the OXM metadata to take into accound ORM mapping metadata,
 */
public void applyORMMetadata(AbstractSession ormSession){
  Iterator ormDescriptors=ormSession.getDescriptors().values().iterator();
  while (ormDescriptors.hasNext()) {
    ClassDescriptor ormDescriptor=(ClassDescriptor)ormDescriptors.next();
    Class javaClass=ormDescriptor.getJavaClass();
    AbstractSession oxmSession=null;
    try {
      oxmSession=this.getSession(javaClass);
    }
 catch (    XMLMarshalException ex) {
    }
    if (oxmSession != null) {
      ClassDescriptor oxmDescriptor=oxmSession.getDescriptor(javaClass);
      Iterator<DatabaseMapping> ormMappings=ormDescriptor.getMappings().iterator();
      while (ormMappings.hasNext()) {
        DatabaseMapping ormMapping=ormMappings.next();
        DatabaseMapping oxmMapping=oxmDescriptor.getMappingForAttributeName(ormMapping.getAttributeName());
        if (oxmMapping != null) {
          AttributeAccessor oxmAccessor=oxmMapping.getAttributeAccessor();
          OrmAttributeAccessor newAccessor=new OrmAttributeAccessor(ormMapping.getAttributeAccessor(),oxmAccessor);
          if (ormMapping.isOneToOneMapping() && ((OneToOneMapping)ormMapping).usesIndirection()) {
            newAccessor.setValueHolderProperty(true);
          }
          newAccessor.setChangeTracking(ormDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
          oxmMapping.setAttributeAccessor(newAccessor);
          AttributeAccessor containerAccessor=null;
          Class containerClass=null;
          if (oxmMapping instanceof XMLCompositeObjectMapping) {
            containerAccessor=((XMLCompositeObjectMapping)oxmMapping).getContainerAccessor();
            containerClass=((XMLCompositeObjectMapping)oxmMapping).getReferenceClass();
          }
 else           if (oxmMapping instanceof XMLCompositeCollectionMapping) {
            containerAccessor=((XMLCompositeCollectionMapping)oxmMapping).getContainerAccessor();
            containerClass=((XMLCompositeCollectionMapping)oxmMapping).getReferenceClass();
          }
          if (containerAccessor != null) {
            ClassDescriptor containerDescriptor=ormSession.getDescriptor(containerClass);
            if (containerDescriptor != null) {
              DatabaseMapping ormContainerMapping=containerDescriptor.getMappingForAttributeName(containerAccessor.getAttributeName());
              if (ormContainerMapping != null) {
                OrmAttributeAccessor ormAccessor=new OrmAttributeAccessor(ormContainerMapping.getAttributeAccessor(),containerAccessor);
                ormAccessor.setChangeTracking(containerDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
                ormAccessor.setValueHolderProperty(ormContainerMapping instanceof OneToOneMapping && ((OneToOneMapping)ormContainerMapping).usesIndirection());
                if (oxmMapping instanceof XMLCompositeObjectMapping) {
                  ((XMLCompositeObjectMapping)oxmMapping).setContainerAccessor(ormAccessor);
                }
 else                 if (oxmMapping instanceof XMLCompositeCollectionMapping) {
                  ((XMLCompositeCollectionMapping)oxmMapping).setContainerAccessor(ormAccessor);
                }
              }
            }
          }
        }
      }
      Iterator<DatabaseMapping> oxmMappingsIterator=oxmDescriptor.getMappings().iterator();
      while (oxmMappingsIterator.hasNext()) {
        DatabaseMapping nextMapping=oxmMappingsIterator.next();
        if (nextMapping instanceof XMLObjectReferenceMapping) {
          XMLObjectReferenceMapping refMapping=(XMLObjectReferenceMapping)nextMapping;
          if (refMapping.getBidirectionalTargetAccessor() != null && refMapping.getBidirectionalTargetContainerPolicy() != null) {
            ClassDescriptor refDescriptor=ormSession.getClassDescriptor(refMapping.getReferenceClass());
            if (refDescriptor != null) {
              DatabaseMapping backpointerMapping=refDescriptor.getMappingForAttributeName(refMapping.getBidirectionalTargetAttributeName());
              if (backpointerMapping != null && backpointerMapping.isCollectionMapping()) {
                refMapping.setBidirectionalTargetContainerClass(((CollectionMapping)backpointerMapping).getContainerPolicy().getContainerClass());
              }
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * ADVANCED: Adjust the OXM metadata to take into accound ORM mapping metadata,
 */
public void applyORMMetadata(AbstractSession ormSession){
  Iterator ormDescriptors=ormSession.getDescriptors().values().iterator();
  while (ormDescriptors.hasNext()) {
    ClassDescriptor ormDescriptor=(ClassDescriptor)ormDescriptors.next();
    Class javaClass=ormDescriptor.getJavaClass();
    AbstractSession oxmSession=null;
    try {
      oxmSession=this.getSession(javaClass);
    }
 catch (    XMLMarshalException ex) {
    }
    if (oxmSession != null) {
      ClassDescriptor oxmDescriptor=oxmSession.getDescriptor(javaClass);
      Iterator<DatabaseMapping> ormMappings=ormDescriptor.getMappings().iterator();
      while (ormMappings.hasNext()) {
        DatabaseMapping ormMapping=ormMappings.next();
        DatabaseMapping oxmMapping=oxmDescriptor.getMappingForAttributeName(ormMapping.getAttributeName());
        if (oxmMapping != null) {
          AttributeAccessor oxmAccessor=oxmMapping.getAttributeAccessor();
          OrmAttributeAccessor newAccessor=new OrmAttributeAccessor(ormMapping.getAttributeAccessor(),oxmAccessor);
          if (ormMapping.isOneToOneMapping() && ((OneToOneMapping)ormMapping).usesIndirection()) {
            newAccessor.setValueHolderProperty(true);
          }
          newAccessor.setChangeTracking(ormDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
          oxmMapping.setAttributeAccessor(newAccessor);
          AttributeAccessor containerAccessor=null;
          Class containerClass=null;
          if (oxmMapping instanceof XMLCompositeObjectMapping) {
            containerAccessor=((XMLCompositeObjectMapping)oxmMapping).getInverseReferenceMapping().getAttributeAccessor();
            containerClass=((XMLCompositeObjectMapping)oxmMapping).getReferenceClass();
          }
 else           if (oxmMapping instanceof XMLCompositeCollectionMapping) {
            containerAccessor=((XMLCompositeCollectionMapping)oxmMapping).getInverseReferenceMapping().getAttributeAccessor();
            containerClass=((XMLCompositeCollectionMapping)oxmMapping).getReferenceClass();
          }
          if (containerAccessor != null) {
            ClassDescriptor containerDescriptor=ormSession.getDescriptor(containerClass);
            if (containerDescriptor != null) {
              DatabaseMapping ormContainerMapping=containerDescriptor.getMappingForAttributeName(containerAccessor.getAttributeName());
              if (ormContainerMapping != null) {
                OrmAttributeAccessor ormAccessor=new OrmAttributeAccessor(ormContainerMapping.getAttributeAccessor(),containerAccessor);
                ormAccessor.setChangeTracking(containerDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
                ormAccessor.setValueHolderProperty(ormContainerMapping instanceof OneToOneMapping && ((OneToOneMapping)ormContainerMapping).usesIndirection());
                if (oxmMapping instanceof XMLCompositeObjectMapping) {
                  ((XMLCompositeObjectMapping)oxmMapping).getInverseReferenceMapping().setAttributeAccessor(ormAccessor);
                }
 else                 if (oxmMapping instanceof XMLCompositeCollectionMapping) {
                  ((XMLCompositeCollectionMapping)oxmMapping).getInverseReferenceMapping().setAttributeAccessor(ormAccessor);
                }
              }
            }
          }
        }
      }
      Iterator<DatabaseMapping> oxmMappingsIterator=oxmDescriptor.getMappings().iterator();
      while (oxmMappingsIterator.hasNext()) {
        DatabaseMapping nextMapping=oxmMappingsIterator.next();
        if (nextMapping instanceof XMLObjectReferenceMapping) {
          XMLObjectReferenceMapping refMapping=(XMLObjectReferenceMapping)nextMapping;
          if (refMapping.getInverseReferenceMapping().getAttributeAccessor() != null && refMapping.getInverseReferenceMapping().getContainerPolicy() != null) {
            ClassDescriptor refDescriptor=ormSession.getClassDescriptor(refMapping.getReferenceClass());
            if (refDescriptor != null) {
              DatabaseMapping backpointerMapping=refDescriptor.getMappingForAttributeName(refMapping.getInverseReferenceMapping().getAttributeName());
              if (backpointerMapping != null && backpointerMapping.isCollectionMapping()) {
                refMapping.getInverseReferenceMapping().getContainerPolicy().setContainerClass(((CollectionMapping)backpointerMapping).getContainerPolicy().getContainerClass());
              }
            }
          }
        }
      }
    }
  }
}