Program: 65040
Project: 65040
Buggy source:
public Object unmarshal(org.xml.sax.XMLReader xmlReader,InputSource inputSource,Class clazz){
  try {
    XMLContext xmlContext=xmlUnmarshaller.getXMLContext();
    if (xmlContext.hasDocumentPreservation()) {
      SAXDocumentBuilder saxDocumentBuilder=new SAXDocumentBuilder();
      xmlReader.setContentHandler(saxDocumentBuilder);
      xmlReader.parse(inputSource);
      return unmarshal(saxDocumentBuilder.getDocument().getDocumentElement(),clazz);
    }
    boolean isPrimitiveWrapper=isPrimitiveWrapper(clazz);
    UnmarshalRecord unmarshalRecord;
    XMLDescriptor xmlDescriptor=null;
    AbstractSession session=null;
    if (isPrimitiveWrapper) {
      unmarshalRecord=new XMLRootRecord(clazz);
      unmarshalRecord.setSession((AbstractSession)xmlUnmarshaller.getXMLContext().getSession(0));
    }
 else     if (clazz == ClassConstants.OBJECT) {
      SAXUnmarshallerHandler saxUnmarshallerHandler=new SAXUnmarshallerHandler(xmlUnmarshaller.getXMLContext());
      saxUnmarshallerHandler.setXMLReader((XMLReader)xmlReader);
      saxUnmarshallerHandler.setUnmarshaller(xmlUnmarshaller);
      saxUnmarshallerHandler.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      xmlReader.setContentHandler(saxUnmarshallerHandler);
      xmlReader.parse(inputSource);
      saxUnmarshallerHandler.resolveReferences();
      return saxUnmarshallerHandler.getObject();
    }
 else {
      session=xmlContext.getReadSession(clazz);
      xmlDescriptor=(XMLDescriptor)session.getDescriptor(clazz);
      unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
    }
    XMLReader extendedXMLReader;
    if (xmlReader instanceof XMLReader) {
      extendedXMLReader=(XMLReader)xmlReader;
    }
 else {
      extendedXMLReader=new XMLReader(xmlReader);
    }
    unmarshalRecord.setXMLReader(extendedXMLReader);
    unmarshalRecord.setUnmarshaller(xmlUnmarshaller);
    setContentHandler(extendedXMLReader,unmarshalRecord);
    extendedXMLReader.setLexicalHandler(unmarshalRecord);
    extendedXMLReader.parse(inputSource);
    xmlUnmarshaller.resolveReferences(session);
    if (isPrimitiveWrapper || clazz == ClassConstants.OBJECT) {
      return unmarshalRecord.getCurrentObject();
    }
    return xmlDescriptor.wrapObjectInXMLRoot(unmarshalRecord,this.isResultAlwaysXMLRoot);
  }
 catch (  IOException e) {
    throw XMLMarshalException.unmarshalException(e);
  }
catch (  SAXException e) {
    throw convertSAXException(e);
  }
 finally {
    xmlUnmarshaller.getStringBuffer().reset();
  }
}

Fixed version (ground truth):
public Object unmarshal(org.xml.sax.XMLReader xmlReader,InputSource inputSource,Class clazz){
  try {
    XMLContext xmlContext=xmlUnmarshaller.getXMLContext();
    if (xmlContext.hasDocumentPreservation()) {
      SAXDocumentBuilder saxDocumentBuilder=new SAXDocumentBuilder();
      xmlReader.setContentHandler(saxDocumentBuilder);
      xmlReader.parse(inputSource);
      return unmarshal(saxDocumentBuilder.getDocument().getDocumentElement(),clazz);
    }
    UnmarshalRecord unmarshalRecord=null;
    XMLDescriptor xmlDescriptor=null;
    AbstractSession session=null;
    boolean isPrimitiveWrapper=false;
    if (clazz == ClassConstants.OBJECT) {
      SAXUnmarshallerHandler saxUnmarshallerHandler=new SAXUnmarshallerHandler(xmlUnmarshaller.getXMLContext());
      saxUnmarshallerHandler.setXMLReader((XMLReader)xmlReader);
      saxUnmarshallerHandler.setUnmarshaller(xmlUnmarshaller);
      saxUnmarshallerHandler.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
      xmlReader.setContentHandler(saxUnmarshallerHandler);
      xmlReader.parse(inputSource);
      saxUnmarshallerHandler.resolveReferences();
      return saxUnmarshallerHandler.getObject();
    }
 else {
      try {
        session=xmlContext.getReadSession(clazz);
        xmlDescriptor=(XMLDescriptor)session.getDescriptor(clazz);
        unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
      }
 catch (      XMLMarshalException xme) {
        if (xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) {
          isPrimitiveWrapper=isPrimitiveWrapper(clazz);
          if (isPrimitiveWrapper) {
            unmarshalRecord=new XMLRootRecord(clazz);
            unmarshalRecord.setSession((AbstractSession)xmlUnmarshaller.getXMLContext().getSession(0));
          }
 else {
            throw xme;
          }
        }
 else {
          throw xme;
        }
      }
    }
    XMLReader extendedXMLReader;
    if (xmlReader instanceof XMLReader) {
      extendedXMLReader=(XMLReader)xmlReader;
    }
 else {
      extendedXMLReader=new XMLReader(xmlReader);
    }
    unmarshalRecord.setXMLReader(extendedXMLReader);
    unmarshalRecord.setUnmarshaller(xmlUnmarshaller);
    setContentHandler(extendedXMLReader,unmarshalRecord);
    extendedXMLReader.setLexicalHandler(unmarshalRecord);
    extendedXMLReader.parse(inputSource);
    xmlUnmarshaller.resolveReferences(session);
    if (isPrimitiveWrapper || clazz == ClassConstants.OBJECT) {
      return unmarshalRecord.getCurrentObject();
    }
    return xmlDescriptor.wrapObjectInXMLRoot(unmarshalRecord,this.isResultAlwaysXMLRoot);
  }
 catch (  IOException e) {
    throw XMLMarshalException.unmarshalException(e);
  }
catch (  SAXException e) {
    throw convertSAXException(e);
  }
 finally {
    xmlUnmarshaller.getStringBuffer().reset();
  }
}