Program: 67059
Project: 67059
Buggy source:
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  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 + XMLConstants.COLON + qName;
        }
      }
    }
  }
  int qNameColonIndex=qName.indexOf(XMLConstants.COLON);
  if ((namespaceURI != null) && (qNameColonIndex == -1)) {
    String prefix=owningRecord.resolveNamespaceUri(namespaceURI);
    if (prefix != null && prefix.length() > 0) {
      qName=prefix + XMLConstants.COLON + qName;
    }
  }
  Element element=getInitializedDocument().createElementNS(namespaceURI,qName);
  Node parentNode=(Node)nodes.peek();
  boolean bufferContainsOnlyWhitespace=stringBuffer.toString().trim().length() == 0;
  if (bufferContainsOnlyWhitespace) {
    stringBuffer.reset();
  }
  appendChildNode(parentNode,element);
  nodes.push(element);
  qNameColonIndex=qName.indexOf(XMLConstants.COLON);
  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(XMLConstants.XMLNS + XMLConstants.COLON)) {
      attributeNamespaceURI=XMLConstants.XMLNS_URL;
    }
    if (attributeNamespaceURI == null) {
      element.setAttribute(atts.getQName(x),atts.getValue(x));
    }
 else {
      String value=atts.getValue(x);
      element.setAttributeNS(attributeNamespaceURI,atts.getQName(x),value);
      if (XMLConstants.SCHEMA_INSTANCE_URL.equals(attributeNamespaceURI) && XMLConstants.SCHEMA_TYPE_ATTRIBUTE.equals(atts.getLocalName(x))) {
        int colonIndex=value.indexOf(XMLConstants.COLON);
        if (colonIndex > -1) {
          String prefix=value.substring(0,colonIndex);
          String uri=XMLPlatformFactory.getInstance().getXMLPlatform().resolveNamespacePrefix(element,prefix);
          if (uri == null || uri.length() == 0) {
            String theUri=owningRecord.resolveNamespacePrefix(prefix);
            if (theUri != null && theUri.length() > 0) {
              element.setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + prefix,theUri);
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  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 + XMLConstants.COLON + qName;
        }
      }
    }
  }
  int qNameColonIndex=qName.indexOf(XMLConstants.COLON);
  if ((namespaceURI != null) && (qNameColonIndex == -1)) {
    String prefix=owningRecord.resolveNamespaceUri(namespaceURI);
    if (prefix != null && prefix.length() > 0) {
      qName=prefix + XMLConstants.COLON + qName;
      qNameColonIndex=prefix.length();
    }
  }
  Element element=getInitializedDocument().createElementNS(namespaceURI,qName);
  Node parentNode=(Node)nodes.peek();
  boolean bufferContainsOnlyWhitespace=stringBuffer.toString().trim().length() == 0;
  if (bufferContainsOnlyWhitespace) {
    stringBuffer.reset();
  }
  appendChildNode(parentNode,element);
  nodes.push(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(XMLConstants.XMLNS + XMLConstants.COLON)) {
      attributeNamespaceURI=XMLConstants.XMLNS_URL;
    }
    if (attributeNamespaceURI == null) {
      element.setAttribute(atts.getQName(x),atts.getValue(x));
    }
 else {
      String value=atts.getValue(x);
      element.setAttributeNS(attributeNamespaceURI,atts.getQName(x),value);
      if (XMLConstants.SCHEMA_INSTANCE_URL.equals(attributeNamespaceURI) && XMLConstants.SCHEMA_TYPE_ATTRIBUTE.equals(atts.getLocalName(x))) {
        int colonIndex=value.indexOf(XMLConstants.COLON);
        if (colonIndex > -1) {
          String prefix=value.substring(0,colonIndex);
          String uri=XMLPlatformFactory.getInstance().getXMLPlatform().resolveNamespacePrefix(element,prefix);
          if (uri == null || uri.length() == 0) {
            String theUri=owningRecord.resolveNamespacePrefix(prefix);
            if (theUri != null && theUri.length() > 0) {
              element.setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + prefix,theUri);
            }
          }
        }
      }
    }
  }
}