Program: 64537
Project: 64537
Buggy source:
private XPathFragment getXPathFragmentForValue(Object value,MarshalRecord marshalRecord,XMLMarshaller marshaller){
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof XMLRoot)) {
    XMLRoot xmlRootValue=(XMLRoot)value;
    XPathFragment xmlRootFragment=new XPathFragment(xmlRootValue.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
    xmlRootFragment.setNamespaceURI(xmlRootValue.getNamespaceURI());
    return xmlRootFragment;
  }
  if (value instanceof Node) {
    XPathFragment frag=null;
    Node n=(Node)value;
    if (n.getNodeType() == Node.ELEMENT_NODE) {
      Element elem=(Element)n;
      String local=elem.getLocalName();
      if (local == null) {
        local=elem.getNodeName();
      }
      String prefix=elem.getPrefix();
      if (prefix != null && !prefix.equals(XMLConstants.EMPTY_STRING)) {
        frag=new XPathFragment(prefix + marshalRecord.getNamespaceSeparator() + elem.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
 else {
        frag=new XPathFragment(local,marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
    }
 else     if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
      Attr attr=(Attr)n;
      attr.getLocalName();
      String prefix=attr.getPrefix();
      if (prefix != null && prefix.equals(XMLConstants.EMPTY_STRING)) {
        frag=new XPathFragment(prefix + marshalRecord.getNamespaceSeparator() + attr.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
 else {
        frag=new XPathFragment(attr.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
    }
 else     if (n.getNodeType() == Node.TEXT_NODE) {
      return SIMPLE_FRAGMENT;
    }
    return frag;
  }
  CoreAbstractSession childSession=null;
  try {
    childSession=marshaller.getXMLContext().getSession(value);
  }
 catch (  XMLMarshalException e) {
    return SIMPLE_FRAGMENT;
  }
  if (childSession != null) {
    XMLDescriptor descriptor=(XMLDescriptor)childSession.getDescriptor(value);
    String defaultRootElementString=descriptor.getDefaultRootElement();
    if (defaultRootElementString != null) {
      return new XPathFragment(defaultRootElementString);
    }
  }
  return null;
}

Fixed version (ground truth):
private XPathFragment getXPathFragmentForValue(Object value,MarshalRecord marshalRecord,XMLMarshaller marshaller){
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof XMLRoot)) {
    XMLRoot xmlRootValue=(XMLRoot)value;
    XPathFragment xmlRootFragment=new XPathFragment(xmlRootValue.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
    xmlRootFragment.setNamespaceURI(xmlRootValue.getNamespaceURI());
    return xmlRootFragment;
  }
  if (value instanceof Node) {
    XPathFragment frag=null;
    Node n=(Node)value;
    if (n.getNodeType() == Node.ELEMENT_NODE) {
      Element elem=(Element)n;
      String local=elem.getLocalName();
      if (local == null) {
        local=elem.getNodeName();
      }
      String prefix=elem.getPrefix();
      if (prefix != null && !prefix.equals(XMLConstants.EMPTY_STRING)) {
        frag=new XPathFragment(prefix + marshalRecord.getNamespaceSeparator() + elem.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
 else {
        frag=new XPathFragment(local,marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
    }
 else     if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
      Attr attr=(Attr)n;
      attr.getLocalName();
      String prefix=attr.getPrefix();
      if (prefix != null && prefix.equals(XMLConstants.EMPTY_STRING)) {
        frag=new XPathFragment(prefix + marshalRecord.getNamespaceSeparator() + attr.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
 else {
        frag=new XPathFragment(attr.getLocalName(),marshalRecord.getNamespaceSeparator(),marshalRecord.isNamespaceAware());
      }
    }
 else     if (n.getNodeType() == Node.TEXT_NODE) {
      return SIMPLE_FRAGMENT;
    }
    return frag;
  }
  CoreAbstractSession childSession=null;
  try {
    childSession=marshaller.getXMLContext().getSession(value);
  }
 catch (  XMLMarshalException e) {
    return SIMPLE_FRAGMENT;
  }
  if (childSession != null) {
    Descriptor descriptor=(Descriptor)childSession.getDescriptor(value);
    String defaultRootElementString=descriptor.getDefaultRootElement();
    if (defaultRootElementString != null) {
      return new XPathFragment(defaultRootElementString);
    }
  }
  return null;
}