Program: 64698
Project: 64698
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) {
      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;
}

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;
  NodeValue nodeValue=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;
        }
      }
    }
    if (associatedField != null) {
      nodeValue=this.fieldToNodeValues.get(associatedField);
    }
  }
 else {
    Class theClass=value.getClass();
    while (associatedField == null) {
      associatedField=xmlChoiceCollectionMapping.getClassToFieldMappings().get(theClass);
      nodeValue=classToNodeValues.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);
      nodeValue=fieldToNodeValues.get(associatedField);
    }
  }
  if (nodeValue != null) {
    return nodeValue;
  }
  if (associatedField != null) {
    return fieldToNodeValues.get(associatedField);
  }
  if (xmlChoiceCollectionMapping.isMixedContent() && value instanceof String) {
    return this;
  }
  return null;
}