Program: 63966
Project: 63966
Buggy source:
/** 
 * Generate a mapping for a given Property.
 * @param property
 * @param descriptor
 * @param namespaceInfo
 * @return newly created mapping
 */
public Mapping generateMapping(Property property,Descriptor descriptor,JavaClass descriptorJavaClass,NamespaceInfo namespaceInfo){
  if (property.isSetXmlJavaTypeAdapter()) {
    if (property.isReference()) {
      return generateMappingForReferenceProperty(property,descriptor,namespaceInfo);
    }
    XmlJavaTypeAdapter xja=property.getXmlJavaTypeAdapter();
    JavaClass adapterClass=helper.getJavaClass(xja.getValue());
    JavaClass valueType=null;
    String sValType=xja.getValueType();
    if (sValType.equals("String_Node_Str")) {
      valueType=property.getActualType();
    }
 else {
      valueType=helper.getJavaClass(xja.getValueType());
    }
    Mapping mapping;
    boolean isArray=property.getType().isArray() && !property.getType().getRawName().equals("String_Node_Str");
    if (property.isChoice()) {
      if (helper.isCollectionType(property.getType())) {
        mapping=generateChoiceCollectionMapping(property,descriptor,namespaceInfo);
        ((ChoiceCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        mapping=generateChoiceMapping(property,descriptor,namespaceInfo);
        ((ChoiceObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
    }
 else     if (typeInfo.containsKey(valueType.getQualifiedName())) {
      TypeInfo reference=typeInfo.get(valueType.getQualifiedName());
      if (helper.isCollectionType(property.getType())) {
        if (reference.isEnumerationType()) {
          mapping=generateEnumCollectionMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
          XMLJavaTypeConverter converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
          converter.setNestedConverter(((DirectCollectionMapping)mapping).getValueConverter());
          ((DirectCollectionMapping)mapping).setValueConverter(converter);
        }
 else {
          if (property.getVariableAttributeName() != null) {
            mapping=generateVariableXPathCollectionMapping(property,descriptor,namespaceInfo,valueType);
            ((VariableXPathCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
 else {
            mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,valueType.getQualifiedName());
            ((CompositeCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
 else {
        if (reference.isEnumerationType()) {
          mapping=generateDirectEnumerationMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
          XMLJavaTypeConverter converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
          converter.setNestedConverter(((DirectMapping)mapping).getConverter());
          ((DirectMapping)mapping).setConverter(converter);
        }
 else         if (property.isInverseReference()) {
          mapping=generateInverseReferenceMapping(property,descriptor,namespaceInfo);
        }
 else {
          if (property.getVariableAttributeName() != null) {
            mapping=generateVariableXPathObjectMapping(property,descriptor,namespaceInfo,valueType);
            ((VariableXPathObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
 else {
            mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,valueType.getQualifiedName());
            ((CompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
    }
 else {
      if (property.isAny()) {
        if (helper.isCollectionType(property.getType())) {
          mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,property.isMixedContent());
          ((AnyCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateAnyObjectMapping(property,descriptor,namespaceInfo);
          ((AnyObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
 else       if (helper.isCollectionType(property.getType()) || isArray) {
        if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
          mapping=generateBinaryDataCollectionMapping(property,descriptor,namespaceInfo);
          ((BinaryDataCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateDirectCollectionMapping(property,descriptor,namespaceInfo);
          if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
            ((DirectCollectionMapping)mapping).setCollapsingStringValues(true);
          }
 else           if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
            ((DirectCollectionMapping)mapping).setNormalizingStringValues(true);
          }
 else {
            ((DirectCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
 else       if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
        mapping=generateBinaryMapping(property,descriptor,namespaceInfo);
        ((BinaryDataMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        if (!property.isAttribute() && areEquals(valueType,Object.class) || property.isTyped()) {
          mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,null);
          ((CompositeObjectMapping)mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
          ((CompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          return mapping;
        }
        mapping=generateDirectMapping(property,descriptor,namespaceInfo);
        if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
          ((DirectMapping)mapping).setCollapsingStringValues(true);
        }
 else         if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
          ((DirectMapping)mapping).setNormalizingStringValues(true);
        }
 else {
          ((DirectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
    }
    return mapping;
  }
  if (property.getVariableAttributeName() != null) {
    if (helper.isCollectionType(property.getType()) || property.getType().isArray() || property.isMap()) {
      return generateVariableXPathCollectionMapping(property,descriptor,namespaceInfo,property.getActualType());
    }
 else {
      return generateVariableXPathObjectMapping(property,descriptor,namespaceInfo,property.getActualType());
    }
  }
  if (property.isSetXmlJoinNodes()) {
    if (helper.isCollectionType(property.getType())) {
      return generateXMLCollectionReferenceMapping(property,descriptor,namespaceInfo,property.getActualType());
    }
    return generateXMLObjectReferenceMapping(property,descriptor,namespaceInfo,property.getType());
  }
  if (property.isXmlTransformation()) {
    return generateTransformationMapping(property,descriptor,namespaceInfo);
  }
  if (property.isChoice()) {
    if (helper.isCollectionType(property.getType())) {
      return generateChoiceCollectionMapping(property,descriptor,namespaceInfo);
    }
    return generateChoiceMapping(property,descriptor,namespaceInfo);
  }
  if (property.isInverseReference()) {
    return generateInverseReferenceMapping(property,descriptor,namespaceInfo);
  }
  if (property.isAny()) {
    if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
      return generateAnyCollectionMapping(property,descriptor,namespaceInfo,property.isMixedContent());
    }
    return generateAnyObjectMapping(property,descriptor,namespaceInfo);
  }
  if (property.isReference()) {
    return generateMappingForReferenceProperty(property,descriptor,namespaceInfo);
  }
  if (property.isMap()) {
    if (property.isAnyAttribute()) {
      return generateAnyAttributeMapping(property,descriptor,namespaceInfo);
    }
    return generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,null);
  }
  if (helper.isCollectionType(property.getType())) {
    return generateCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo);
  }
  JavaClass referenceClass=property.getType();
  String referenceClassName=referenceClass.getRawName();
  if (referenceClass.isArray() && !referenceClassName.equals("String_Node_Str")) {
    JavaClass componentType=referenceClass.getComponentType();
    TypeInfo reference=typeInfo.get(componentType.getName());
    if (reference != null && reference.isEnumerationType()) {
      return generateEnumCollectionMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
    }
    if (areEquals(componentType,Object.class)) {
      CompositeCollectionMapping mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,null);
      mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      return mapping;
    }
    if (reference != null || componentType.isArray()) {
      if (property.isXmlIdRef() || property.isSetXmlJoinNodes()) {
        return generateXMLCollectionReferenceMapping(property,descriptor,namespaceInfo,componentType);
      }
      return generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,componentType.getQualifiedName());
    }
    return generateDirectCollectionMapping(property,descriptor,namespaceInfo);
  }
  if (property.isXmlIdRef()) {
    return generateXMLObjectReferenceMapping(property,descriptor,namespaceInfo,referenceClass);
  }
  TypeInfo reference=typeInfo.get(referenceClass.getQualifiedName());
  if (reference != null) {
    if (reference.isEnumerationType()) {
      return generateDirectEnumerationMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
    }
    if (property.isXmlLocation()) {
      CompositeObjectMapping locationMapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,referenceClass.getQualifiedName());
      reference.getDescriptor().setInstantiationPolicy(new NullInstantiationPolicy());
      descriptor.setLocationAccessor((CoreAttributeAccessor)locationMapping.getAttributeAccessor());
      return locationMapping;
    }
 else {
      return generateCompositeObjectMapping(property,descriptor,namespaceInfo,referenceClass.getQualifiedName());
    }
  }
  if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
    return generateBinaryMapping(property,descriptor,namespaceInfo);
  }
  if (referenceClass.getQualifiedName().equals(OBJECT_CLASS_NAME) && !property.isAttribute() || property.isTyped()) {
    CompositeObjectMapping coMapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,null);
    coMapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
    return coMapping;
  }
  if (property.isXmlLocation()) {
    return null;
  }
  return generateDirectMapping(property,descriptor,namespaceInfo);
}

Fixed version (ground truth):
/** 
 * Generate a mapping for a given Property.
 * @param property
 * @param descriptor
 * @param namespaceInfo
 * @return newly created mapping
 */
public Mapping generateMapping(Property property,Descriptor descriptor,JavaClass descriptorJavaClass,NamespaceInfo namespaceInfo){
  if (property.isSetXmlJavaTypeAdapter()) {
    if (property.isReference()) {
      return generateMappingForReferenceProperty(property,descriptor,namespaceInfo);
    }
    XmlJavaTypeAdapter xja=property.getXmlJavaTypeAdapter();
    JavaClass adapterClass=helper.getJavaClass(xja.getValue());
    JavaClass valueType=null;
    String sValType=xja.getValueType();
    if (sValType.equals("String_Node_Str")) {
      valueType=property.getActualType();
    }
 else {
      valueType=helper.getJavaClass(xja.getValueType());
    }
    Mapping mapping;
    boolean isArray=property.getType().isArray() && !property.getType().getRawName().equals("String_Node_Str");
    if (property.isChoice()) {
      if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
        mapping=generateChoiceCollectionMapping(property,descriptor,namespaceInfo);
        ((ChoiceCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        mapping=generateChoiceMapping(property,descriptor,namespaceInfo);
        ((ChoiceObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
    }
 else     if (typeInfo.containsKey(valueType.getQualifiedName())) {
      TypeInfo reference=typeInfo.get(valueType.getQualifiedName());
      if (helper.isCollectionType(property.getType())) {
        if (reference.isEnumerationType()) {
          mapping=generateEnumCollectionMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
          XMLJavaTypeConverter converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
          converter.setNestedConverter(((DirectCollectionMapping)mapping).getValueConverter());
          ((DirectCollectionMapping)mapping).setValueConverter(converter);
        }
 else {
          if (property.getVariableAttributeName() != null) {
            mapping=generateVariableXPathCollectionMapping(property,descriptor,namespaceInfo,valueType);
            ((VariableXPathCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
 else {
            mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,valueType.getQualifiedName());
            ((CompositeCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
 else {
        if (reference.isEnumerationType()) {
          mapping=generateDirectEnumerationMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
          XMLJavaTypeConverter converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
          converter.setNestedConverter(((DirectMapping)mapping).getConverter());
          ((DirectMapping)mapping).setConverter(converter);
        }
 else         if (property.isInverseReference()) {
          mapping=generateInverseReferenceMapping(property,descriptor,namespaceInfo);
        }
 else {
          if (property.getVariableAttributeName() != null) {
            mapping=generateVariableXPathObjectMapping(property,descriptor,namespaceInfo,valueType);
            ((VariableXPathObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
 else {
            mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,valueType.getQualifiedName());
            ((CompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
    }
 else {
      if (property.isAny()) {
        if (helper.isCollectionType(property.getType())) {
          mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,property.isMixedContent());
          ((AnyCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateAnyObjectMapping(property,descriptor,namespaceInfo);
          ((AnyObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
 else       if (helper.isCollectionType(property.getType()) || isArray) {
        if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
          mapping=generateBinaryDataCollectionMapping(property,descriptor,namespaceInfo);
          ((BinaryDataCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateDirectCollectionMapping(property,descriptor,namespaceInfo);
          if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
            ((DirectCollectionMapping)mapping).setCollapsingStringValues(true);
          }
 else           if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
            ((DirectCollectionMapping)mapping).setNormalizingStringValues(true);
          }
 else {
            ((DirectCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
 else       if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
        mapping=generateBinaryMapping(property,descriptor,namespaceInfo);
        ((BinaryDataMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        if (!property.isAttribute() && areEquals(valueType,Object.class) || property.isTyped()) {
          mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,null);
          ((CompositeObjectMapping)mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
          ((CompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          return mapping;
        }
        mapping=generateDirectMapping(property,descriptor,namespaceInfo);
        if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
          ((DirectMapping)mapping).setCollapsingStringValues(true);
        }
 else         if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
          ((DirectMapping)mapping).setNormalizingStringValues(true);
        }
 else {
          ((DirectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
    }
    return mapping;
  }
  if (property.getVariableAttributeName() != null) {
    if (helper.isCollectionType(property.getType()) || property.getType().isArray() || property.isMap()) {
      return generateVariableXPathCollectionMapping(property,descriptor,namespaceInfo,property.getActualType());
    }
 else {
      return generateVariableXPathObjectMapping(property,descriptor,namespaceInfo,property.getActualType());
    }
  }
  if (property.isSetXmlJoinNodes()) {
    if (helper.isCollectionType(property.getType())) {
      return generateXMLCollectionReferenceMapping(property,descriptor,namespaceInfo,property.getActualType());
    }
    return generateXMLObjectReferenceMapping(property,descriptor,namespaceInfo,property.getType());
  }
  if (property.isXmlTransformation()) {
    return generateTransformationMapping(property,descriptor,namespaceInfo);
  }
  if (property.isChoice()) {
    if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
      return generateChoiceCollectionMapping(property,descriptor,namespaceInfo);
    }
    return generateChoiceMapping(property,descriptor,namespaceInfo);
  }
  if (property.isInverseReference()) {
    return generateInverseReferenceMapping(property,descriptor,namespaceInfo);
  }
  if (property.isAny()) {
    if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
      return generateAnyCollectionMapping(property,descriptor,namespaceInfo,property.isMixedContent());
    }
    return generateAnyObjectMapping(property,descriptor,namespaceInfo);
  }
  if (property.isReference()) {
    return generateMappingForReferenceProperty(property,descriptor,namespaceInfo);
  }
  if (property.isMap()) {
    if (property.isAnyAttribute()) {
      return generateAnyAttributeMapping(property,descriptor,namespaceInfo);
    }
    return generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,null);
  }
  if (helper.isCollectionType(property.getType())) {
    return generateCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo);
  }
  JavaClass referenceClass=property.getType();
  String referenceClassName=referenceClass.getRawName();
  if (referenceClass.isArray() && !referenceClassName.equals("String_Node_Str")) {
    JavaClass componentType=referenceClass.getComponentType();
    TypeInfo reference=typeInfo.get(componentType.getName());
    if (reference != null && reference.isEnumerationType()) {
      return generateEnumCollectionMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
    }
    if (areEquals(componentType,Object.class)) {
      CompositeCollectionMapping mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,null);
      mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      return mapping;
    }
    if (reference != null || componentType.isArray()) {
      if (property.isXmlIdRef() || property.isSetXmlJoinNodes()) {
        return generateXMLCollectionReferenceMapping(property,descriptor,namespaceInfo,componentType);
      }
      return generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,componentType.getQualifiedName());
    }
    return generateDirectCollectionMapping(property,descriptor,namespaceInfo);
  }
  if (property.isXmlIdRef()) {
    return generateXMLObjectReferenceMapping(property,descriptor,namespaceInfo,referenceClass);
  }
  TypeInfo reference=typeInfo.get(referenceClass.getQualifiedName());
  if (reference != null) {
    if (reference.isEnumerationType()) {
      return generateDirectEnumerationMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
    }
    if (property.isXmlLocation()) {
      CompositeObjectMapping locationMapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,referenceClass.getQualifiedName());
      reference.getDescriptor().setInstantiationPolicy(new NullInstantiationPolicy());
      descriptor.setLocationAccessor((CoreAttributeAccessor)locationMapping.getAttributeAccessor());
      return locationMapping;
    }
 else {
      return generateCompositeObjectMapping(property,descriptor,namespaceInfo,referenceClass.getQualifiedName());
    }
  }
  if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
    return generateBinaryMapping(property,descriptor,namespaceInfo);
  }
  if (referenceClass.getQualifiedName().equals(OBJECT_CLASS_NAME) && !property.isAttribute() || property.isTyped()) {
    CompositeObjectMapping coMapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,null);
    coMapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
    return coMapping;
  }
  if (property.isXmlLocation()) {
    return null;
  }
  return generateDirectMapping(property,descriptor,namespaceInfo);
}