Program: 65067
Project: 65067
Buggy source:
private NodeValue getNodeValueForValue(Object value){
  XMLField associatedField=null;
  if (value instanceof XMLRoot) {
    XMLRoot rootValue=(XMLRoot)value;
    String localName=rootValue.getLocalName();
    String namespaceUri=rootValue.getNamespaceURI();
    Object fieldValue=rootValue.getObject();
    associatedField=getFieldForName(localName,namespaceUri);
    if (associatedField == null) {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(fieldValue.getClass());
    }
  }
 else {
    associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(value.getClass());
  }
  if (associatedField == null) {
    List<XMLField> sourceFields=xmlChoiceCollectionMapping.getClassToSourceFieldsMappings().get(value.getClass());
    if (sourceFields != null) {
      associatedField=sourceFields.get(0);
    }
  }
  if (associatedField != null) {
    return fieldToNodeValues.get(associatedField);
  }
  if (xmlChoiceCollectionMapping.isMixedContent() && value instanceof String) {
    return this;
  }
  return null;
}

Fixed version (ground truth):
private NodeValue getNodeValueForValue(Object value){
  if (value == null) {
    Iterator<NodeValue> nodeValues=fieldToNodeValues.values().iterator();
    while (nodeValues.hasNext()) {
      XMLChoiceCollectionMappingUnmarshalNodeValue unmarshalNodeValue=(XMLChoiceCollectionMappingUnmarshalNodeValue)nodeValues.next();
      NodeValue nextNodeValue=unmarshalNodeValue.getChoiceElementMarshalNodeValue();
      if (nextNodeValue instanceof MappingNodeValue) {
        DatabaseMapping nextMapping=((MappingNodeValue)nextNodeValue).getMapping();
        if (nextMapping.isAbstractCompositeCollectionMapping()) {
          if (((XMLCompositeCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
 else         if (nextMapping.isAbstractCompositeDirectCollectionMapping()) {
          if (((XMLCompositeDirectCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
 else         if (nextMapping instanceof XMLBinaryDataCollectionMapping) {
          if (((XMLBinaryDataCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
      }
    }
    return null;
  }
  XMLField associatedField=null;
  if (value instanceof XMLRoot) {
    XMLRoot rootValue=(XMLRoot)value;
    String localName=rootValue.getLocalName();
    String namespaceUri=rootValue.getNamespaceURI();
    Object fieldValue=rootValue.getObject();
    associatedField=getFieldForName(localName,namespaceUri);
    if (associatedField == null) {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(fieldValue.getClass());
    }
  }
 else {
    associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(value.getClass());
  }
  if (associatedField == null) {
    List<XMLField> sourceFields=xmlChoiceCollectionMapping.getClassToSourceFieldsMappings().get(value.getClass());
    if (sourceFields != null) {
      associatedField=sourceFields.get(0);
    }
  }
  if (associatedField != null) {
    return fieldToNodeValues.get(associatedField);
  }
  if (xmlChoiceCollectionMapping.isMixedContent() && value instanceof String) {
    return this;
  }
  return null;
}