Program: 67219
Project: 67219
Buggy source:
public XMLMapping generateMappingForReferenceProperty(ReferenceProperty property,XMLDescriptor descriptor,NamespaceInfo namespaceInfo){
  if (property.isMixedContent()) {
    XMLAnyCollectionMapping mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,true);
    return mapping;
  }
  boolean isCollection=isCollectionType(property);
  DatabaseMapping mapping;
  if (isCollection) {
    mapping=new XMLChoiceCollectionMapping();
  }
 else {
    mapping=new XMLChoiceObjectMapping();
  }
  mapping.setAttributeName(property.getPropertyName());
  if (property.isMethodProperty()) {
    if (property.getGetMethodName() == null) {
      String paramTypeAsString=property.getType().getName();
      mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString,helper.getClassLoader()));
      mapping.setIsReadOnly(true);
      mapping.setSetMethodName(property.getSetMethodName());
    }
 else     if (property.getSetMethodName() == null) {
      mapping.setGetMethodName(property.getGetMethodName());
      ((XMLMapping)mapping).setIsWriteOnly(true);
    }
 else {
      mapping.setSetMethodName(property.getSetMethodName());
      mapping.setGetMethodName(property.getGetMethodName());
    }
  }
  List<ElementDeclaration> referencedElements=property.getReferencedElements();
  boolean hasJAXBElements=false;
  AttributeAccessor mappingAccessor=mapping.getAttributeAccessor();
  Map<QName,Class> qNamesToScopeClass=new HashMap<QName,Class>();
  for (  ElementDeclaration element : referencedElements) {
    QName elementName=element.getElementName();
    boolean isText=!(this.typeInfo.containsKey(element.getJavaTypeName())) && !(element.getJavaTypeName().equals(OBJECT_CLASS_NAME));
    XMLField xmlField=this.getXPathForElement("String_Node_Str",elementName,namespaceInfo,isText);
    if (helper.getXMLToJavaTypeMap().get(element.getJavaType().getRawName()) == XMLConstants.BASE_64_BINARY_QNAME) {
      xmlField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    }
    XMLMapping nestedMapping;
    JAXBElementAttributeAccessor nestedAccessor;
    if (isCollection) {
      nestedAccessor=new JAXBElementAttributeAccessor(mappingAccessor,mapping.getContainerPolicy());
      ((XMLChoiceCollectionMapping)mapping).addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=((XMLChoiceCollectionMapping)mapping).getChoiceElementMappings().get(xmlField);
      if (((DatabaseMapping)nestedMapping).isAbstractCompositeCollectionMapping()) {
        ((XMLCompositeCollectionMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
      if (((DatabaseMapping)nestedMapping).isAbstractCompositeDirectCollectionMapping()) {
        ((XMLCompositeDirectCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByEmptyNode(false);
      }
      if (element.isList() && ((DatabaseMapping)nestedMapping).isAbstractCompositeDirectCollectionMapping()) {
        XMLListConverter listConverter=new XMLListConverter();
        listConverter.setObjectClassName(element.getJavaType().getQualifiedName());
        ((XMLCompositeDirectCollectionMapping)nestedMapping).setValueConverter(listConverter);
      }
    }
 else {
      nestedAccessor=new JAXBElementAttributeAccessor(mappingAccessor);
      ((XMLChoiceObjectMapping)mapping).addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=((XMLChoiceObjectMapping)mapping).getChoiceElementMappings().get(xmlField);
      if (((DatabaseMapping)nestedMapping).isAbstractCompositeObjectMapping()) {
        ((XMLCompositeObjectMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
    }
    if (!element.isXmlRootElement()) {
      XMLRootConverter converter=new XMLRootConverter(xmlField);
      if (isCollection) {
        ((XMLChoiceCollectionMapping)mapping).addConverter(xmlField,converter);
      }
 else {
        ((XMLChoiceObjectMapping)mapping).addConverter(xmlField,converter);
      }
      Class scopeClass=element.getScopeClass();
      if (scopeClass == javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class) {
        scopeClass=JAXBElement.GlobalScope.class;
      }
      qNamesToScopeClass.put(elementName,scopeClass);
    }
    hasJAXBElements=hasJAXBElements || !element.isXmlRootElement();
    Class theClass;
    theClass=helper.getClassForJavaClass(element.getJavaType());
    nestedAccessor.setDeclaredType(theClass);
    nestedAccessor.setQNamesToScopes(qNamesToScopeClass);
    ((DatabaseMapping)nestedMapping).setAttributeAccessor(nestedAccessor);
  }
  if (hasJAXBElements) {
    JAXBElementAttributeAccessor accessor;
    if (isCollection) {
      accessor=new JAXBElementAttributeAccessor(mappingAccessor,mapping.getContainerPolicy());
    }
 else {
      accessor=new JAXBElementAttributeAccessor(mappingAccessor);
    }
    Class theClass=helper.getClassForJavaClass(property.getActualType());
    accessor.setDeclaredType(theClass);
    accessor.setQNamesToScopes(qNamesToScopeClass);
    mapping.setAttributeAccessor(accessor);
  }
  descriptor.addMapping(mapping);
  return (XMLMapping)mapping;
}

Fixed version (ground truth):
public XMLMapping generateMappingForReferenceProperty(ReferenceProperty property,XMLDescriptor descriptor,NamespaceInfo namespaceInfo){
  if (property.isMixedContent()) {
    XMLAnyCollectionMapping mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,true);
    return mapping;
  }
  boolean isCollection=isCollectionType(property) || property.getType().isArray();
  DatabaseMapping mapping;
  if (isCollection) {
    mapping=new XMLChoiceCollectionMapping();
  }
 else {
    mapping=new XMLChoiceObjectMapping();
  }
  mapping.setAttributeName(property.getPropertyName());
  if (property.isMethodProperty()) {
    if (property.getGetMethodName() == null) {
      String paramTypeAsString=property.getType().getName();
      mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString,helper.getClassLoader()));
      mapping.setIsReadOnly(true);
      mapping.setSetMethodName(property.getSetMethodName());
    }
 else     if (property.getSetMethodName() == null) {
      mapping.setGetMethodName(property.getGetMethodName());
      ((XMLMapping)mapping).setIsWriteOnly(true);
    }
 else {
      mapping.setSetMethodName(property.getSetMethodName());
      mapping.setGetMethodName(property.getGetMethodName());
    }
  }
  List<ElementDeclaration> referencedElements=property.getReferencedElements();
  boolean hasJAXBElements=false;
  AttributeAccessor mappingAccessor=mapping.getAttributeAccessor();
  if (property.getType().isArray()) {
    JAXBObjectArrayAttributeAccessor accessor=new JAXBObjectArrayAttributeAccessor(mappingAccessor,mapping.getContainerPolicy());
    accessor.setComponentClassName(property.getType().getComponentType().getRawName());
    mappingAccessor=accessor;
  }
  Map<QName,Class> qNamesToScopeClass=new HashMap<QName,Class>();
  for (  ElementDeclaration element : referencedElements) {
    QName elementName=element.getElementName();
    boolean isText=!(this.typeInfo.containsKey(element.getJavaTypeName())) && !(element.getJavaTypeName().equals(OBJECT_CLASS_NAME));
    XMLField xmlField=this.getXPathForElement("String_Node_Str",elementName,namespaceInfo,isText);
    if (helper.getXMLToJavaTypeMap().get(element.getJavaType().getRawName()) == XMLConstants.BASE_64_BINARY_QNAME) {
      xmlField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    }
    XMLMapping nestedMapping;
    JAXBElementAttributeAccessor nestedAccessor;
    if (isCollection) {
      nestedAccessor=new JAXBElementAttributeAccessor(mappingAccessor,mapping.getContainerPolicy());
      ((XMLChoiceCollectionMapping)mapping).addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=((XMLChoiceCollectionMapping)mapping).getChoiceElementMappings().get(xmlField);
      if (((DatabaseMapping)nestedMapping).isAbstractCompositeCollectionMapping()) {
        ((XMLCompositeCollectionMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
      if (((DatabaseMapping)nestedMapping).isAbstractCompositeDirectCollectionMapping()) {
        ((XMLCompositeDirectCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByEmptyNode(false);
      }
      if (element.isList() && ((DatabaseMapping)nestedMapping).isAbstractCompositeDirectCollectionMapping()) {
        XMLListConverter listConverter=new XMLListConverter();
        listConverter.setObjectClassName(element.getJavaType().getQualifiedName());
        ((XMLCompositeDirectCollectionMapping)nestedMapping).setValueConverter(listConverter);
      }
    }
 else {
      nestedAccessor=new JAXBElementAttributeAccessor(mappingAccessor);
      ((XMLChoiceObjectMapping)mapping).addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=((XMLChoiceObjectMapping)mapping).getChoiceElementMappings().get(xmlField);
      if (((DatabaseMapping)nestedMapping).isAbstractCompositeObjectMapping()) {
        ((XMLCompositeObjectMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
    }
    if (!element.isXmlRootElement()) {
      XMLRootConverter converter=new XMLRootConverter(xmlField);
      if (isCollection) {
        ((XMLChoiceCollectionMapping)mapping).addConverter(xmlField,converter);
      }
 else {
        ((XMLChoiceObjectMapping)mapping).addConverter(xmlField,converter);
      }
      Class scopeClass=element.getScopeClass();
      if (scopeClass == javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class) {
        scopeClass=JAXBElement.GlobalScope.class;
      }
      qNamesToScopeClass.put(elementName,scopeClass);
    }
    hasJAXBElements=hasJAXBElements || !element.isXmlRootElement();
    Class theClass;
    theClass=helper.getClassForJavaClass(element.getJavaType());
    nestedAccessor.setDeclaredType(theClass);
    nestedAccessor.setQNamesToScopes(qNamesToScopeClass);
    ((DatabaseMapping)nestedMapping).setAttributeAccessor(nestedAccessor);
  }
  if (hasJAXBElements) {
    JAXBElementAttributeAccessor accessor;
    if (isCollection) {
      accessor=new JAXBElementAttributeAccessor(mappingAccessor,mapping.getContainerPolicy());
    }
 else {
      accessor=new JAXBElementAttributeAccessor(mappingAccessor);
    }
    Class theClass=helper.getClassForJavaClass(property.getActualType());
    accessor.setDeclaredType(theClass);
    accessor.setQNamesToScopes(qNamesToScopeClass);
    mapping.setAttributeAccessor(accessor);
  }
  descriptor.addMapping(mapping);
  return (XMLMapping)mapping;
}