Program: 63634
Project: 63634
Buggy source:
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  boolean bufferContainsOnlyWhitespace=stringBuffer.toString().trim().length() == 0;
  if (bufferContainsOnlyWhitespace) {
    stringBuffer.reset();
  }
  if ((stringBuffer.length() > 0) && !(nodes.size() == 1)) {
    Text text=getInitializedDocument().createTextNode(stringBuffer.toString());
    Node parent=this.nodes.get(nodes.size() - 1);
    parent.appendChild(text);
    processNamespacesForText(text.getTextContent(),(Element)parent);
    stringBuffer.reset();
  }
  if (null != namespaceURI && namespaceURI.length() == 0) {
    namespaceURI=null;
  }
  if (qName == null) {
    qName=localName;
    if (namespaceURI != null) {
      if (owningRecord != null) {
        String prefix=owningRecord.resolveNamespaceUri(namespaceURI);
        if (prefix != null && prefix.length() > 0) {
          qName=prefix + Constants.COLON + qName;
        }
      }
    }
  }
  int qNameColonIndex=qName.indexOf(Constants.COLON);
  if ((namespaceURI != null) && (qNameColonIndex == -1)) {
    String prefix=owningRecord.resolveNamespaceUri(namespaceURI);
    if (prefix != null && prefix.length() > 0) {
      qName=prefix + Constants.COLON + qName;
      qNameColonIndex=prefix.length();
    }
  }
  Element element=getInitializedDocument().createElementNS(namespaceURI,qName);
  Node parentNode=nodes.get(nodes.size() - 1);
  appendChildNode(parentNode,element);
  nodes.add(element);
  if (qNameColonIndex > -1) {
    String prefix=qName.substring(0,qNameColonIndex);
    String parentUri=null;
    if (element.getParentNode() != null) {
      parentUri=XMLPlatformFactory.getInstance().getXMLPlatform().resolveNamespacePrefix(element.getParentNode(),prefix);
    }
    if ((parentUri == null) || parentUri.length() == 0) {
      startPrefixMapping(prefix,namespaceURI);
    }
  }
  if (null != namespaceDeclarations) {
    Iterator namespaces=namespaceDeclarations.entrySet().iterator();
    while (namespaces.hasNext()) {
      Map.Entry entry=(Map.Entry)namespaces.next();
      addNamespaceDeclaration(element,(String)entry.getKey(),(String)entry.getValue());
    }
    namespaceDeclarations=null;
  }
  int numberOfAttributes=atts.getLength();
  String attributeNamespaceURI;
  for (int x=0; x < numberOfAttributes; x++) {
    attributeNamespaceURI=atts.getURI(x);
    if (null != attributeNamespaceURI && attributeNamespaceURI.length() == 0) {
      attributeNamespaceURI=null;
    }
    if (attributeNamespaceURI == null && atts.getQName(x).startsWith(javax.xml.XMLConstants.XMLNS_ATTRIBUTE + Constants.COLON)) {
      attributeNamespaceURI=javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }
    String value=atts.getValue(x);
    if (attributeNamespaceURI == null) {
      element.setAttribute(atts.getQName(x),value);
    }
 else {
      element.setAttributeNS(attributeNamespaceURI,atts.getQName(x),value == null ? Constants.EMPTY_STRING : value);
    }
    if (value != null) {
      processNamespacesForText(value,element);
    }
  }
}

Fixed version (ground truth):
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  boolean bufferContainsOnlyWhitespace=stringBuffer.toString().trim().length() == 0;
  if (bufferContainsOnlyWhitespace) {
    stringBuffer.reset();
  }
  if ((stringBuffer.length() > 0) && !(nodes.size() == 1)) {
    Text text=getInitializedDocument().createTextNode(stringBuffer.toString());
    Node parent=this.nodes.get(nodes.size() - 1);
    parent.appendChild(text);
    processNamespacesForText(text.getTextContent(),(Element)parent);
    stringBuffer.reset();
  }
  if (null != namespaceURI && namespaceURI.length() == 0) {
    namespaceURI=null;
  }
  if (qName == null) {
    qName=localName;
    if (namespaceURI != null) {
      if (owningRecord != null) {
        String prefix=owningRecord.resolveNamespaceUri(namespaceURI);
        if (prefix != null && prefix.length() > 0) {
          qName=prefix + Constants.COLON + qName;
        }
      }
    }
  }
  int qNameColonIndex=qName.indexOf(Constants.COLON);
  if ((namespaceURI != null) && (qNameColonIndex == -1)) {
    String prefix=owningRecord.resolveNamespaceUri(namespaceURI);
    if (prefix != null && prefix.length() > 0) {
      qName=prefix + Constants.COLON + qName;
      qNameColonIndex=prefix.length();
    }
  }
  Element element=getInitializedDocument().createElementNS(namespaceURI,qName);
  Node parentNode=nodes.get(nodes.size() - 1);
  appendChildNode(parentNode,element);
  nodes.add(element);
  if (qNameColonIndex > -1) {
    String prefix=qName.substring(0,qNameColonIndex);
    String parentUri=null;
    if (element.getParentNode() != null) {
      parentUri=XMLPlatformFactory.getInstance().getXMLPlatform().resolveNamespacePrefix(element.getParentNode(),prefix);
    }
    if ((parentUri == null) || parentUri.length() == 0) {
      startPrefixMapping(prefix,namespaceURI);
    }
  }
  if (null != namespaceDeclarations) {
    Iterator namespaces=namespaceDeclarations.entrySet().iterator();
    while (namespaces.hasNext()) {
      Map.Entry entry=(Map.Entry)namespaces.next();
      addNamespaceDeclaration(element,(String)entry.getKey(),(String)entry.getValue());
    }
    namespaceDeclarations=null;
  }
  int numberOfAttributes=atts.getLength();
  String attributeNamespaceURI, attributeQName, attributeValue;
  for (int x=0; x < numberOfAttributes; x++) {
    attributeNamespaceURI=atts.getURI(x);
    attributeQName=atts.getQName(x);
    attributeValue=atts.getValue(x);
    if (null != attributeNamespaceURI && attributeNamespaceURI.length() == 0) {
      attributeNamespaceURI=null;
    }
    if (attributeNamespaceURI == null && attributeQName.startsWith(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) {
      attributeNamespaceURI=javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }
    element.setAttributeNS(attributeNamespaceURI,attributeQName,attributeValue == null ? Constants.EMPTY_STRING : attributeValue);
    if (attributeValue != null) {
      processNamespacesForText(attributeValue,element);
    }
  }
}