Program: 64570
Project: 64570
Buggy source:
/** 
 * Generate a mapping for a given Property.
 * @param property
 * @param descriptor
 * @param namespaceInfo
 * @return newly created mapping
 */
public DatabaseMapping generateMapping(Property property,XMLDescriptor 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());
    }
    DatabaseMapping mapping;
    boolean isArray=property.getType().isArray() && !property.getType().getRawName().equals("String_Node_Str");
    if (property.isChoice()) {
      if (isCollectionType(property)) {
        mapping=generateChoiceCollectionMapping(property,descriptor,namespaceInfo);
        ((XMLChoiceCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        mapping=generateChoiceMapping(property,descriptor,namespaceInfo);
        ((XMLChoiceObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
    }
 else     if (typeInfo.containsKey(valueType.getQualifiedName())) {
      TypeInfo reference=typeInfo.get(valueType.getQualifiedName());
      if (isCollectionType(property)) {
        if (reference.isEnumerationType()) {
          mapping=generateEnumCollectionMapping(property,descriptor,namespaceInfo,(EnumTypeInfo)reference);
          XMLJavaTypeConverter converter=new XMLJavaTypeConverter(adapterClass.getQualifiedName());
          converter.setNestedConverter(((XMLCompositeDirectCollectionMapping)mapping).getValueConverter());
          ((XMLCompositeDirectCollectionMapping)mapping).setValueConverter(converter);
        }
 else {
          mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,valueType.getQualifiedName());
          ((XMLCompositeCollectionMapping)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(((XMLDirectMapping)mapping).getConverter());
          ((XMLDirectMapping)mapping).setConverter(converter);
        }
 else         if (property.isInverseReference()) {
          mapping=generateInverseReferenceMapping(property,descriptor,namespaceInfo);
        }
 else {
          mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,valueType.getQualifiedName());
          ((XMLCompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
    }
 else {
      if (property.isAny()) {
        if (isCollectionType(property)) {
          mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,property.isMixedContent());
          ((XMLAnyCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateAnyObjectMapping(property,descriptor,namespaceInfo);
          ((XMLAnyObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
 else       if (isCollectionType(property) || isArray) {
        if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
          mapping=generateBinaryDataCollectionMapping(property,descriptor,namespaceInfo);
          ((XMLBinaryDataCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateDirectCollectionMapping(property,descriptor,namespaceInfo);
          if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
            ((XMLCompositeDirectCollectionMapping)mapping).setCollapsingStringValues(true);
          }
 else           if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
            ((XMLCompositeDirectCollectionMapping)mapping).setNormalizingStringValues(true);
          }
 else {
            ((XMLCompositeDirectCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
 else       if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
        mapping=generateBinaryMapping(property,descriptor,namespaceInfo);
        ((XMLBinaryDataMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        if (!property.isAttribute() && areEquals(valueType,Object.class)) {
          mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,null);
          ((XMLCompositeObjectMapping)mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
          ((XMLCompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          return mapping;
        }
        mapping=generateDirectMapping(property,descriptor,namespaceInfo);
        if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
          ((XMLDirectMapping)mapping).setCollapsingStringValues(true);
        }
 else         if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
          ((XMLDirectMapping)mapping).setNormalizingStringValues(true);
        }
 else {
          ((XMLDirectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
    }
    return mapping;
  }
  if (property.isSetXmlJoinNodes()) {
    if (isCollectionType(property)) {
      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 (this.isCollectionType(property)) {
      return generateChoiceCollectionMapping(property,descriptor,namespaceInfo);
    }
    return generateChoiceMapping(property,descriptor,namespaceInfo);
  }
  if (property.isInverseReference()) {
    return generateInverseReferenceMapping(property,descriptor,namespaceInfo);
  }
  if (property.isAny()) {
    if (isCollectionType(property) || 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 generateMapMapping(property,descriptor,descriptorJavaClass,namespaceInfo);
  }
  if (isCollectionType(property)) {
    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)) {
      XMLCompositeCollectionMapping mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,null);
      mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      return mapping;
    }
    if (reference != null || componentType.isArray()) {
      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()) {
      XMLCompositeObjectMapping locationMapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,referenceClass.getQualifiedName());
      reference.getDescriptor().setInstantiationPolicy(new NullInstantiationPolicy());
      descriptor.setLocationAccessor(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()) {
    XMLCompositeObjectMapping 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 DatabaseMapping generateMapping(Property property,XMLDescriptor 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());
    }
    DatabaseMapping 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);
        ((XMLChoiceCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        mapping=generateChoiceMapping(property,descriptor,namespaceInfo);
        ((XMLChoiceObjectMapping)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(((XMLCompositeDirectCollectionMapping)mapping).getValueConverter());
          ((XMLCompositeDirectCollectionMapping)mapping).setValueConverter(converter);
        }
 else {
          mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,valueType.getQualifiedName());
          ((XMLCompositeCollectionMapping)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(((XMLDirectMapping)mapping).getConverter());
          ((XMLDirectMapping)mapping).setConverter(converter);
        }
 else         if (property.isInverseReference()) {
          mapping=generateInverseReferenceMapping(property,descriptor,namespaceInfo);
        }
 else {
          mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,valueType.getQualifiedName());
          ((XMLCompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
    }
 else {
      if (property.isAny()) {
        if (helper.isCollectionType(property.getType())) {
          mapping=generateAnyCollectionMapping(property,descriptor,namespaceInfo,property.isMixedContent());
          ((XMLAnyCollectionMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateAnyObjectMapping(property,descriptor,namespaceInfo);
          ((XMLAnyObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
 else       if (helper.isCollectionType(property.getType()) || isArray) {
        if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
          mapping=generateBinaryDataCollectionMapping(property,descriptor,namespaceInfo);
          ((XMLBinaryDataCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
 else {
          mapping=generateDirectCollectionMapping(property,descriptor,namespaceInfo);
          if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
            ((XMLCompositeDirectCollectionMapping)mapping).setCollapsingStringValues(true);
          }
 else           if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
            ((XMLCompositeDirectCollectionMapping)mapping).setNormalizingStringValues(true);
          }
 else {
            ((XMLCompositeDirectCollectionMapping)mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          }
        }
      }
 else       if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
        mapping=generateBinaryMapping(property,descriptor,namespaceInfo);
        ((XMLBinaryDataMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
      }
 else {
        if (!property.isAttribute() && areEquals(valueType,Object.class)) {
          mapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,null);
          ((XMLCompositeObjectMapping)mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
          ((XMLCompositeObjectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
          return mapping;
        }
        mapping=generateDirectMapping(property,descriptor,namespaceInfo);
        if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
          ((XMLDirectMapping)mapping).setCollapsingStringValues(true);
        }
 else         if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
          ((XMLDirectMapping)mapping).setNormalizingStringValues(true);
        }
 else {
          ((XMLDirectMapping)mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
      }
    }
    return mapping;
  }
  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 generateMapMapping(property,descriptor,descriptorJavaClass,namespaceInfo);
  }
  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)) {
      XMLCompositeCollectionMapping mapping=generateCompositeCollectionMapping(property,descriptor,descriptorJavaClass,namespaceInfo,null);
      mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      return mapping;
    }
    if (reference != null || componentType.isArray()) {
      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()) {
      XMLCompositeObjectMapping locationMapping=generateCompositeObjectMapping(property,descriptor,namespaceInfo,referenceClass.getQualifiedName());
      reference.getDescriptor().setInstantiationPolicy(new NullInstantiationPolicy());
      descriptor.setLocationAccessor(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()) {
    XMLCompositeObjectMapping 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);
}