Program: 63967
Project: 63967
Buggy source:
public ChoiceCollectionMapping generateChoiceCollectionMapping(Property property,Descriptor descriptor,NamespaceInfo namespace){
  ChoiceCollectionMapping mapping=new XMLChoiceCollectionMapping();
  initializeXMLContainerMapping(mapping,property.getType().isArray());
  initializeXMLMapping((XMLChoiceCollectionMapping)mapping,property);
  JavaClass collectionType=property.getType();
  collectionType=containerClassImpl(collectionType);
  mapping.useCollectionClassName(collectionType.getRawName());
  if (property.isSetXmlElementWrapper()) {
    mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
  }
  boolean isIdRef=property.isXmlIdRef();
  Iterator<Property> choiceProperties=property.getChoiceProperties().iterator();
  while (choiceProperties.hasNext()) {
    Property next=choiceProperties.next();
    JavaClass type=next.getType();
    JavaClass originalType=next.getType();
    Converter converter=null;
    Field xmlField=null;
    TypeInfo info=typeInfo.get(type.getName());
    if (info != null) {
      XmlJavaTypeAdapter adapter=info.getXmlJavaTypeAdapter();
      if (adapter != null) {
        String adapterValue=adapter.getValue();
        JavaClass adapterClass=helper.getJavaClass(adapterValue);
        JavaClass theClass=CompilerHelper.getTypeFromAdapterClass(adapterClass,helper);
        type=theClass;
        converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
      }
    }
    if (next.getXmlJoinNodes() != null) {
      List<Field> srcFlds=new ArrayList<Field>();
      List<Field> tgtFlds=new ArrayList<Field>();
      for (      XmlJoinNode xmlJoinNode : next.getXmlJoinNodes().getXmlJoinNode()) {
        srcFlds.add(new XMLField(xmlJoinNode.getXmlPath()));
        tgtFlds.add(new XMLField(xmlJoinNode.getReferencedXmlPath()));
      }
      mapping.addChoiceElement(srcFlds,type.getQualifiedName(),tgtFlds);
    }
 else     if (isIdRef) {
      String tgtXPath=null;
      TypeInfo referenceType=typeInfo.get(type.getQualifiedName());
      if (null != referenceType && referenceType.isIDSet()) {
        Property prop=referenceType.getIDProperty();
        tgtXPath=getXPathForField(prop,namespace,!prop.isAttribute(),false).getXPath();
      }
      Field srcXPath;
      if (next.getXmlPath() != null) {
        srcXPath=new XMLField(next.getXmlPath());
      }
 else {
        srcXPath=getXPathForField(next,namespace,true,false);
      }
      mapping.addChoiceElement(srcXPath.getXPath(),type.getQualifiedName(),tgtXPath);
    }
 else {
      Field xpath;
      if (next.getXmlPath() != null) {
        xpath=new XMLField(next.getXmlPath());
      }
 else {
        xpath=getXPathForField(next,namespace,(!(this.typeInfo.containsKey(type.getQualifiedName()))) || type.isEnum(),false);
      }
      xmlField=xpath;
      mapping.addChoiceElement(xpath.getName(),type.getQualifiedName());
      if (!originalType.getQualifiedName().equals(type.getQualifiedName())) {
        if (mapping.getClassNameToFieldMappings().get(originalType.getQualifiedName()) == null) {
          mapping.getClassNameToFieldMappings().put(originalType.getQualifiedName(),xpath);
        }
        mapping.addConverter(xpath,converter);
      }
    }
    if (xmlField != null) {
      Mapping nestedMapping=(Mapping)mapping.getChoiceElementMappings().get(xmlField);
      if (nestedMapping.isAbstractCompositeCollectionMapping()) {
        if (property.isSetNullPolicy()) {
          ((CompositeCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(property,namespace.getNamespaceResolverForDescriptor()));
        }
 else         if (next.isNillable() && property.isNillable()) {
          ((CompositeCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByXsiNil(true);
          ((CompositeCollectionMapping)nestedMapping).getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
      }
 else       if (nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
        if (next.isSetNullPolicy()) {
          ((DirectCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(next,namespace.getNamespaceResolverForDescriptor()));
        }
 else         if (next.isNillable() && property.isNillable()) {
          ((DirectCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByXsiNil(true);
          ((DirectCollectionMapping)nestedMapping).getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
        if (type.isEnum()) {
          ((DirectCollectionMapping)nestedMapping).setValueConverter(buildJAXBEnumTypeConverter(nestedMapping,(EnumTypeInfo)info));
        }
      }
 else       if (nestedMapping instanceof BinaryDataCollectionMapping) {
        if (next.isSetNullPolicy()) {
          ((BinaryDataCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(next,namespace.getNamespaceResolverForDescriptor()));
        }
 else         if (next.isNillable() && property.isNillable()) {
          ((BinaryDataCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByXsiNil(true);
          ((BinaryDataCollectionMapping)nestedMapping).getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
      }
    }
  }
  return mapping;
}

Fixed version (ground truth):
public ChoiceCollectionMapping generateChoiceCollectionMapping(Property property,Descriptor descriptor,NamespaceInfo namespace){
  ChoiceCollectionMapping mapping=new XMLChoiceCollectionMapping();
  initializeXMLContainerMapping(mapping,property.getType().isArray());
  initializeXMLMapping((XMLChoiceCollectionMapping)mapping,property);
  JavaClass collectionType=property.getType();
  if (collectionType.isArray()) {
    JAXBArrayAttributeAccessor accessor=new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(),mapping.getContainerPolicy(),helper.getClassLoader());
    JavaClass componentType=collectionType.getComponentType();
    if (componentType.isArray()) {
      JavaClass baseComponentType=getBaseComponentType(componentType);
      if (baseComponentType.isPrimitive()) {
        Class primitiveClass=XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
        accessor.setComponentClass(primitiveClass);
      }
 else {
        accessor.setComponentClassName(baseComponentType.getQualifiedName());
      }
    }
 else {
      accessor.setComponentClassName(componentType.getQualifiedName());
    }
    mapping.setAttributeAccessor(accessor);
  }
  collectionType=containerClassImpl(collectionType);
  mapping.useCollectionClassName(collectionType.getRawName());
  if (property.isSetXmlElementWrapper()) {
    mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
  }
  boolean isIdRef=property.isXmlIdRef();
  Iterator<Property> choiceProperties=property.getChoiceProperties().iterator();
  while (choiceProperties.hasNext()) {
    Property next=choiceProperties.next();
    JavaClass type=next.getType();
    JavaClass originalType=next.getType();
    Converter converter=null;
    Field xmlField=null;
    TypeInfo info=typeInfo.get(type.getName());
    if (info != null) {
      XmlJavaTypeAdapter adapter=info.getXmlJavaTypeAdapter();
      if (adapter != null) {
        String adapterValue=adapter.getValue();
        JavaClass adapterClass=helper.getJavaClass(adapterValue);
        JavaClass theClass=CompilerHelper.getTypeFromAdapterClass(adapterClass,helper);
        type=theClass;
        converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
      }
    }
    if (next.getXmlJoinNodes() != null) {
      List<Field> srcFlds=new ArrayList<Field>();
      List<Field> tgtFlds=new ArrayList<Field>();
      for (      XmlJoinNode xmlJoinNode : next.getXmlJoinNodes().getXmlJoinNode()) {
        srcFlds.add(new XMLField(xmlJoinNode.getXmlPath()));
        tgtFlds.add(new XMLField(xmlJoinNode.getReferencedXmlPath()));
      }
      mapping.addChoiceElement(srcFlds,type.getQualifiedName(),tgtFlds);
    }
 else     if (isIdRef) {
      String tgtXPath=null;
      TypeInfo referenceType=typeInfo.get(type.getQualifiedName());
      if (null != referenceType && referenceType.isIDSet()) {
        Property prop=referenceType.getIDProperty();
        tgtXPath=getXPathForField(prop,namespace,!prop.isAttribute(),false).getXPath();
      }
      Field srcXPath;
      if (next.getXmlPath() != null) {
        srcXPath=new XMLField(next.getXmlPath());
      }
 else {
        srcXPath=getXPathForField(next,namespace,true,false);
      }
      mapping.addChoiceElement(srcXPath.getXPath(),type.getQualifiedName(),tgtXPath);
    }
 else {
      Field xpath;
      if (next.getXmlPath() != null) {
        xpath=new XMLField(next.getXmlPath());
      }
 else {
        xpath=getXPathForField(next,namespace,(!(this.typeInfo.containsKey(type.getQualifiedName()))) || type.isEnum(),false);
      }
      xmlField=xpath;
      mapping.addChoiceElement(xpath.getName(),type.getQualifiedName());
      if (!originalType.getQualifiedName().equals(type.getQualifiedName())) {
        if (mapping.getClassNameToFieldMappings().get(originalType.getQualifiedName()) == null) {
          mapping.getClassNameToFieldMappings().put(originalType.getQualifiedName(),xpath);
        }
        mapping.addConverter(xpath,converter);
      }
    }
    if (xmlField != null) {
      Mapping nestedMapping=(Mapping)mapping.getChoiceElementMappings().get(xmlField);
      if (nestedMapping.isAbstractCompositeCollectionMapping()) {
        if (property.isSetNullPolicy()) {
          ((CompositeCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(property,namespace.getNamespaceResolverForDescriptor()));
        }
 else         if (next.isNillable() && property.isNillable()) {
          ((CompositeCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByXsiNil(true);
          ((CompositeCollectionMapping)nestedMapping).getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
      }
 else       if (nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
        if (next.isSetNullPolicy()) {
          ((DirectCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(next,namespace.getNamespaceResolverForDescriptor()));
        }
 else         if (next.isNillable() && property.isNillable()) {
          ((DirectCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByXsiNil(true);
          ((DirectCollectionMapping)nestedMapping).getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
        if (type.isEnum()) {
          ((DirectCollectionMapping)nestedMapping).setValueConverter(buildJAXBEnumTypeConverter(nestedMapping,(EnumTypeInfo)info));
        }
      }
 else       if (nestedMapping instanceof BinaryDataCollectionMapping) {
        if (next.isSetNullPolicy()) {
          ((BinaryDataCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(next,namespace.getNamespaceResolverForDescriptor()));
        }
 else         if (next.isNillable() && property.isNillable()) {
          ((BinaryDataCollectionMapping)nestedMapping).getNullPolicy().setNullRepresentedByXsiNil(true);
          ((BinaryDataCollectionMapping)nestedMapping).getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
      }
    }
  }
  return mapping;
}