Program: 63521
Project: 63521
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) {
        Mapping nextMapping=((MappingNodeValue)nextNodeValue).getMapping();
        if (nextMapping.isAbstractCompositeCollectionMapping()) {
          if (((CompositeCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
 else         if (nextMapping.isAbstractCompositeDirectCollectionMapping()) {
          if (((DirectCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
 else         if (nextMapping instanceof BinaryDataCollectionMapping) {
          if (((BinaryDataCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
      }
    }
    return null;
  }
  Field associatedField=null;
  NodeValue nodeValue=null;
  if (value instanceof Root) {
    Root rootValue=(Root)value;
    String localName=rootValue.getLocalName();
    String namespaceUri=rootValue.getNamespaceURI();
    Object fieldValue=rootValue.getObject();
    associatedField=getFieldForName(localName,namespaceUri);
    if (associatedField == null) {
      if (xmlChoiceCollectionMapping.isAny()) {
        return this.anyNodeValue;
      }
      Class theClass=fieldValue.getClass();
      while (associatedField == null) {
        associatedField=(Field)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=(Field)xmlChoiceCollectionMapping.getClassToFieldMappings().get(theClass);
      nodeValue=classToNodeValues.get(theClass);
      if (theClass.getSuperclass() != null) {
        theClass=theClass.getSuperclass();
      }
 else {
        break;
      }
    }
  }
  if (associatedField == null) {
    List<Field> sourceFields=null;
    Class theClass=value.getClass();
    while (theClass != null) {
      sourceFields=(List<Field>)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;
  }
  if (xmlChoiceCollectionMapping.isAny()) {
    return anyNodeValue;
  }
  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) {
        Mapping nextMapping=((MappingNodeValue)nextNodeValue).getMapping();
        if (nextMapping.isAbstractCompositeCollectionMapping()) {
          if (((CompositeCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
 else         if (nextMapping.isAbstractCompositeDirectCollectionMapping()) {
          if (((DirectCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
 else         if (nextMapping instanceof BinaryDataCollectionMapping) {
          if (((BinaryDataCollectionMapping)nextMapping).getNullPolicy().isNullRepresentedByXsiNil()) {
            return unmarshalNodeValue;
          }
        }
      }
    }
    return null;
  }
  Field associatedField=null;
  NodeValue nodeValue=null;
  if (value instanceof Root) {
    Root rootValue=(Root)value;
    String localName=rootValue.getLocalName();
    String namespaceUri=rootValue.getNamespaceURI();
    Object fieldValue=rootValue.getObject();
    associatedField=getFieldForName(localName,namespaceUri);
    if (associatedField == null) {
      if (xmlChoiceCollectionMapping.isAny()) {
        return this.anyNodeValue;
      }
      Class theClass=fieldValue.getClass();
      while (associatedField == null) {
        associatedField=(Field)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=(Field)xmlChoiceCollectionMapping.getClassToFieldMappings().get(theClass);
      List<FieldNodeValue> fieldNodes=classToNodeValues.get(theClass);
      nodeValue=null;
      if (null != fieldNodes) {
        if (null != associatedField && fieldNodes.size() > 1) {
          for (          FieldNodeValue fieldNode : fieldNodes) {
            if (fieldNode.getField().equals(associatedField)) {
              nodeValue=fieldNode.getNodeValue();
            }
          }
        }
        if (null == nodeValue && fieldNodes.size() > 0) {
          nodeValue=fieldNodes.get(0).getNodeValue();
        }
      }
      if (theClass.getSuperclass() != null) {
        theClass=theClass.getSuperclass();
      }
 else {
        break;
      }
    }
  }
  if (associatedField == null) {
    List<Field> sourceFields=null;
    Class theClass=value.getClass();
    while (theClass != null) {
      sourceFields=(List<Field>)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;
  }
  if (xmlChoiceCollectionMapping.isAny()) {
    return anyNodeValue;
  }
  return null;
}