Program: 66215
Project: 66215
Buggy source:
public DatabaseMapping generateMappingForReferenceProperty(Property property,XMLDescriptor descriptor,NamespaceInfo namespaceInfo){
  if (property.isMixedContent() || property.isAny()) {
    XMLAnyCollectionMapping mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,true);
    return mapping;
  }
  boolean isCollection=isCollectionType(property) || property.getType().isArray();
  DatabaseMapping mapping;
  if (isCollection) {
    mapping=new XMLChoiceCollectionMapping();
    ((XMLChoiceCollectionMapping)mapping).setReuseContainer(true);
    ((XMLChoiceCollectionMapping)mapping).setConverter(new JAXBElementRootConverter(Object.class));
    if (property.isSetWriteOnly()) {
      ((XMLChoiceCollectionMapping)mapping).setIsWriteOnly(property.isWriteOnly());
    }
  }
 else {
    mapping=new XMLChoiceObjectMapping();
    ((XMLChoiceObjectMapping)mapping).setConverter(new JAXBElementRootConverter(Object.class));
    if (property.isSetWriteOnly()) {
      ((XMLChoiceObjectMapping)mapping).setIsWriteOnly(property.isWriteOnly());
    }
  }
  if (property.isSetReadOnly()) {
    mapping.setIsReadOnly(property.isReadOnly());
  }
  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();
  JavaClass propertyType=property.getType();
  if (propertyType.isArray()) {
    JAXBArrayAttributeAccessor accessor=new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(),mapping.getContainerPolicy(),helper.getClassLoader());
    accessor.setComponentClassName(property.getType().getComponentType().getName());
    JavaClass componentType=propertyType.getComponentType();
    if (componentType.isArray()) {
      Class adaptedClass=classToGeneratedClasses.get(componentType.getName());
      accessor.setAdaptedClassName(adaptedClass.getName());
    }
    mapping.setAttributeAccessor(accessor);
  }
  for (  ElementDeclaration element : referencedElements) {
    QName elementName=element.getElementName();
    boolean isText=!(this.typeInfo.containsKey(element.getJavaTypeName())) && !(element.getJavaTypeName().equals(OBJECT_CLASS_NAME));
    String xPath="String_Node_Str";
    if (property.isSetXmlElementWrapper()) {
      XmlElementWrapper wrapper=property.getXmlElementWrapper();
      String namespace=wrapper.getNamespace();
      if (namespace.equals("String_Node_Str")) {
        if (namespaceInfo.isElementFormQualified()) {
          namespace=namespaceInfo.getNamespace();
        }
 else {
          namespace="String_Node_Str";
        }
      }
      if (namespace.equals("String_Node_Str")) {
        xPath+=(wrapper.getName() + "String_Node_Str");
      }
 else {
        String prefix=getPrefixForNamespace(namespace,namespaceInfo.getNamespaceResolver(),null);
        xPath+=getQualifiedString(prefix,wrapper.getName() + "String_Node_Str");
      }
    }
    XMLField xmlField=this.getXPathForElement(xPath,elementName,namespaceInfo,isText);
    if (helper.getXMLToJavaTypeMap().get(element.getJavaType().getRawName()) == XMLConstants.BASE_64_BINARY_QNAME) {
      xmlField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    }
    DatabaseMapping nestedMapping;
    if (isCollection) {
      XMLChoiceCollectionMapping xmlChoiceCollectionMapping=(XMLChoiceCollectionMapping)mapping;
      xmlChoiceCollectionMapping.addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=(DatabaseMapping)xmlChoiceCollectionMapping.getChoiceElementMappings().get(xmlField);
      if (nestedMapping.isAbstractCompositeCollectionMapping()) {
        ((XMLCompositeCollectionMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
      if (nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
        ((XMLCompositeDirectCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByEmptyNode(false);
      }
      if (element.isList() && nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
        XMLListConverter listConverter=new XMLListConverter();
        listConverter.setObjectClassName(element.getJavaType().getQualifiedName());
        ((XMLCompositeDirectCollectionMapping)nestedMapping).setValueConverter(listConverter);
      }
    }
 else {
      XMLChoiceObjectMapping xmlChoiceObjectMapping=(XMLChoiceObjectMapping)mapping;
      xmlChoiceObjectMapping.addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=(DatabaseMapping)xmlChoiceObjectMapping.getChoiceElementMappings().get(xmlField);
      if (nestedMapping.isAbstractCompositeObjectMapping()) {
        ((XMLCompositeObjectMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
    }
    if (!element.isXmlRootElement()) {
      Class scopeClass=element.getScopeClass();
      if (scopeClass == javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class) {
        scopeClass=JAXBElement.GlobalScope.class;
      }
      Class declaredType=helper.getClassForJavaClass(element.getJavaType());
      JAXBElementConverter converter=new JAXBElementConverter(xmlField,declaredType,scopeClass);
      if (isCollection) {
        XMLChoiceCollectionMapping xmlChoiceCollectionMapping=(XMLChoiceCollectionMapping)mapping;
        Converter originalConverter=xmlChoiceCollectionMapping.getConverter(xmlField);
        converter.setNestedConverter(originalConverter);
        xmlChoiceCollectionMapping.addConverter(xmlField,converter);
      }
 else {
        XMLChoiceObjectMapping xmlChoiceObjectMapping=(XMLChoiceObjectMapping)mapping;
        Converter originalConverter=xmlChoiceObjectMapping.getConverter(xmlField);
        converter.setNestedConverter(originalConverter);
        xmlChoiceObjectMapping.addConverter(xmlField,converter);
      }
    }
  }
  return mapping;
}

Fixed version (ground truth):
public DatabaseMapping generateMappingForReferenceProperty(Property property,XMLDescriptor descriptor,NamespaceInfo namespaceInfo){
  if (property.isMixedContent() || property.isAny()) {
    XMLAnyCollectionMapping mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,true);
    return mapping;
  }
  boolean isCollection=isCollectionType(property) || property.getType().isArray();
  DatabaseMapping mapping;
  if (isCollection) {
    mapping=new XMLChoiceCollectionMapping();
    ((XMLChoiceCollectionMapping)mapping).setReuseContainer(true);
    ((XMLChoiceCollectionMapping)mapping).useCollectionClassName(jotArrayList.getRawName());
    ((XMLChoiceCollectionMapping)mapping).setConverter(new JAXBElementRootConverter(Object.class));
    if (property.isSetWriteOnly()) {
      ((XMLChoiceCollectionMapping)mapping).setIsWriteOnly(property.isWriteOnly());
    }
  }
 else {
    mapping=new XMLChoiceObjectMapping();
    ((XMLChoiceObjectMapping)mapping).setConverter(new JAXBElementRootConverter(Object.class));
    if (property.isSetWriteOnly()) {
      ((XMLChoiceObjectMapping)mapping).setIsWriteOnly(property.isWriteOnly());
    }
  }
  if (property.isSetReadOnly()) {
    mapping.setIsReadOnly(property.isReadOnly());
  }
  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();
  JavaClass propertyType=property.getType();
  if (propertyType.isArray()) {
    JAXBArrayAttributeAccessor accessor=new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(),mapping.getContainerPolicy(),helper.getClassLoader());
    accessor.setComponentClassName(property.getType().getComponentType().getName());
    JavaClass componentType=propertyType.getComponentType();
    if (componentType.isArray()) {
      Class adaptedClass=classToGeneratedClasses.get(componentType.getName());
      accessor.setAdaptedClassName(adaptedClass.getName());
    }
    mapping.setAttributeAccessor(accessor);
  }
  for (  ElementDeclaration element : referencedElements) {
    QName elementName=element.getElementName();
    boolean isText=!(this.typeInfo.containsKey(element.getJavaTypeName())) && !(element.getJavaTypeName().equals(OBJECT_CLASS_NAME));
    String xPath="String_Node_Str";
    if (property.isSetXmlElementWrapper()) {
      XmlElementWrapper wrapper=property.getXmlElementWrapper();
      String namespace=wrapper.getNamespace();
      if (namespace.equals("String_Node_Str")) {
        if (namespaceInfo.isElementFormQualified()) {
          namespace=namespaceInfo.getNamespace();
        }
 else {
          namespace="String_Node_Str";
        }
      }
      if (namespace.equals("String_Node_Str")) {
        xPath+=(wrapper.getName() + "String_Node_Str");
      }
 else {
        String prefix=getPrefixForNamespace(namespace,namespaceInfo.getNamespaceResolver(),null);
        xPath+=getQualifiedString(prefix,wrapper.getName() + "String_Node_Str");
      }
    }
    XMLField xmlField=this.getXPathForElement(xPath,elementName,namespaceInfo,isText);
    if (helper.getXMLToJavaTypeMap().get(element.getJavaType().getRawName()) == XMLConstants.BASE_64_BINARY_QNAME) {
      xmlField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    }
    DatabaseMapping nestedMapping;
    if (isCollection) {
      XMLChoiceCollectionMapping xmlChoiceCollectionMapping=(XMLChoiceCollectionMapping)mapping;
      xmlChoiceCollectionMapping.addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=(DatabaseMapping)xmlChoiceCollectionMapping.getChoiceElementMappings().get(xmlField);
      if (nestedMapping.isAbstractCompositeCollectionMapping()) {
        ((XMLCompositeCollectionMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
      if (nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
        ((XMLCompositeDirectCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByEmptyNode(false);
      }
      if (element.isList() && nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
        XMLListConverter listConverter=new XMLListConverter();
        listConverter.setObjectClassName(element.getJavaType().getQualifiedName());
        ((XMLCompositeDirectCollectionMapping)nestedMapping).setValueConverter(listConverter);
      }
    }
 else {
      XMLChoiceObjectMapping xmlChoiceObjectMapping=(XMLChoiceObjectMapping)mapping;
      xmlChoiceObjectMapping.addChoiceElement(xmlField,element.getJavaTypeName());
      nestedMapping=(DatabaseMapping)xmlChoiceObjectMapping.getChoiceElementMappings().get(xmlField);
      if (nestedMapping.isAbstractCompositeObjectMapping()) {
        ((XMLCompositeObjectMapping)nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      }
    }
    if (!element.isXmlRootElement()) {
      Class scopeClass=element.getScopeClass();
      if (scopeClass == javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class) {
        scopeClass=JAXBElement.GlobalScope.class;
      }
      Class declaredType=helper.getClassForJavaClass(element.getJavaType());
      JAXBElementConverter converter=new JAXBElementConverter(xmlField,declaredType,scopeClass);
      if (isCollection) {
        XMLChoiceCollectionMapping xmlChoiceCollectionMapping=(XMLChoiceCollectionMapping)mapping;
        Converter originalConverter=xmlChoiceCollectionMapping.getConverter(xmlField);
        converter.setNestedConverter(originalConverter);
        xmlChoiceCollectionMapping.addConverter(xmlField,converter);
      }
 else {
        XMLChoiceObjectMapping xmlChoiceObjectMapping=(XMLChoiceObjectMapping)mapping;
        Converter originalConverter=xmlChoiceObjectMapping.getConverter(xmlField);
        converter.setNestedConverter(originalConverter);
        xmlChoiceObjectMapping.addConverter(xmlField,converter);
      }
    }
  }
  return mapping;
}