Program: 64359
Project: 64359
Buggy source:
public Object unmarshal(org.xml.sax.XMLReader xmlReader,InputSource inputSource,Class clazz){
  try {
    Context 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;
    Descriptor xmlDescriptor=null;
    CoreAbstractSession session=null;
    boolean isPrimitiveWrapper=false;
    if (clazz == CoreClassConstants.OBJECT) {
      SAXUnmarshallerHandler saxUnmarshallerHandler=new SAXUnmarshallerHandler(xmlUnmarshaller.getXMLContext());
      saxUnmarshallerHandler.setXMLReader((XMLReader)xmlReader);
      saxUnmarshallerHandler.setUnmarshaller(xmlUnmarshaller);
      saxUnmarshallerHandler.setKeepAsElementPolicy(KEEP_UNKNOWN_AS_ELEMENT);
      xmlReader.setContentHandler(saxUnmarshallerHandler);
      xmlReader.parse(inputSource);
      saxUnmarshallerHandler.resolveReferences();
      return saxUnmarshallerHandler.getObject();
    }
 else {
      try {
        session=xmlContext.getReadSession(clazz);
        xmlDescriptor=(Descriptor)session.getDescriptor(clazz);
        unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord((AbstractSession)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);
    unmarshalRecord.resolveReferences(session,xmlUnmarshaller.getIDResolver());
    if (isPrimitiveWrapper || clazz == CoreClassConstants.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 {
    Context xmlContext=xmlUnmarshaller.getXMLContext();
    if (xmlContext.hasDocumentPreservation() || (Node.class.isAssignableFrom(clazz) && xmlUnmarshaller.getMediaType().isApplicationXML())) {
      SAXDocumentBuilder saxDocumentBuilder=new SAXDocumentBuilder();
      xmlReader.setContentHandler(saxDocumentBuilder);
      xmlReader.parse(inputSource);
      return unmarshal(saxDocumentBuilder.getDocument().getDocumentElement(),clazz);
    }
    UnmarshalRecord unmarshalRecord=null;
    Descriptor xmlDescriptor=null;
    CoreAbstractSession session=null;
    boolean isPrimitiveWrapper=false;
    if (clazz == CoreClassConstants.OBJECT) {
      SAXUnmarshallerHandler saxUnmarshallerHandler=new SAXUnmarshallerHandler(xmlUnmarshaller.getXMLContext());
      saxUnmarshallerHandler.setXMLReader((XMLReader)xmlReader);
      saxUnmarshallerHandler.setUnmarshaller(xmlUnmarshaller);
      saxUnmarshallerHandler.setKeepAsElementPolicy(KEEP_UNKNOWN_AS_ELEMENT);
      xmlReader.setContentHandler(saxUnmarshallerHandler);
      xmlReader.parse(inputSource);
      saxUnmarshallerHandler.resolveReferences();
      return saxUnmarshallerHandler.getObject();
    }
 else {
      try {
        session=xmlContext.getReadSession(clazz);
        xmlDescriptor=(Descriptor)session.getDescriptor(clazz);
        unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord((AbstractSession)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);
    unmarshalRecord.resolveReferences(session,xmlUnmarshaller.getIDResolver());
    if (isPrimitiveWrapper || clazz == CoreClassConstants.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();
  }
}