Program: 64979
Project: 64979
Buggy source:
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;
}

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) {
      Class theClass=fieldValue.getClass();
      while (associatedField == null) {
        associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(theClass);
        if (theClass.getSuperclass() != null) {
          theClass=theClass.getSuperclass();
        }
 else {
          break;
        }
      }
    }
  }
 else {
    Class theClass=value.getClass();
    while (associatedField == null) {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(theClass);
      if (theClass.getSuperclass() != null) {
        theClass=theClass.getSuperclass();
      }
 else {
        break;
      }
    }
  }
  if (associatedField == null) {
    List<XMLField> sourceFields=null;
    Class theClass=value.getClass();
    while (theClass != null) {
      sourceFields=xmlChoiceCollectionMapping.getClassToSourceFieldsMappings().get(theClass);
      if (sourceFields != null) {
        break;
      }
      theClass=theClass.getSuperclass();
    }
    if (sourceFields != null) {
      associatedField=sourceFields.get(0);
    }
  }
  if (associatedField != null) {
    return fieldToNodeValues.get(associatedField);
  }
  if (xmlChoiceCollectionMapping.isMixedContent() && value instanceof String) {
    return this;
  }
  return null;
}