Program: 65270
Project: 65270
Buggy source:
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  try {
    XMLDescriptor xmlDescriptor=null;
    boolean isPrimitiveType=false;
    Class primitiveWrapperClass=null;
    String type=null;
    if (xmlReader.isNamespaceAware()) {
      type=atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
    }
 else {
      type=atts.getValue(XMLConstants.EMPTY_STRING,XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
    }
    if (null != type) {
      XPathFragment typeFragment=new XPathFragment(type,xmlReader.namespaceSeparator,xmlReader.isNamespaceAware());
      if (xmlReader.isNamespaceAware() && null != unmarshalNamespaceResolver) {
        typeFragment.setNamespaceURI(unmarshalNamespaceResolver.getNamespaceURI(typeFragment.getPrefix()));
      }
      xmlDescriptor=xmlContext.getDescriptorByGlobalType(typeFragment);
      if (xmlDescriptor == null) {
        primitiveWrapperClass=(Class)XMLConversionManager.getDefaultXMLTypes().get(new QName(typeFragment.getNamespaceURI(),typeFragment.getLocalName()));
      }
    }
    if (xmlDescriptor == null) {
      String name;
      if (localName == null || localName.length() == 0) {
        name=qName;
      }
 else {
        name=localName;
      }
      XPathQName rootQName;
      if (namespaceURI == null || namespaceURI.length() == 0) {
        rootQName=new XPathQName(name,xmlReader.isNamespaceAware());
      }
 else {
        rootQName=new XPathQName(namespaceURI,name,xmlReader.isNamespaceAware());
      }
      xmlDescriptor=xmlContext.getDescriptor(rootQName);
      if (null == xmlDescriptor) {
        Object obj=this.xmlReader.getCurrentObject(session,null);
        if (obj != null) {
          xmlDescriptor=(XMLDescriptor)xmlContext.getSession(obj.getClass()).getDescriptor(obj.getClass());
        }
        if (xmlDescriptor == null) {
          isPrimitiveType=primitiveWrapperClass != null;
        }
      }
      if (null == xmlDescriptor && !isPrimitiveType) {
        if (this.keepAsElementPolicy != UnmarshalKeepAsElementPolicy.KEEP_NONE_AS_ELEMENT) {
          this.documentBuilder=new SAXDocumentBuilder();
          documentBuilder.startDocument();
          for (          String prefix : this.unmarshalNamespaceResolver.getPrefixes()) {
            documentBuilder.startPrefixMapping(prefix,this.unmarshalNamespaceResolver.getNamespaceURI(prefix));
          }
          documentBuilder.startElement(namespaceURI,localName,qName,atts);
          this.xmlReader.setContentHandler(documentBuilder);
          return;
        }
        Class unmappedContentHandlerClass=unmarshaller.getUnmappedContentHandlerClass();
        if (null == unmappedContentHandlerClass) {
          throw XMLMarshalException.noDescriptorWithMatchingRootElement(rootQName.toString());
        }
 else {
          UnmappedContentHandler unmappedContentHandler;
          try {
            PrivilegedNewInstanceFromClass privilegedNewInstanceFromClass=new PrivilegedNewInstanceFromClass(unmappedContentHandlerClass);
            unmappedContentHandler=(UnmappedContentHandler)privilegedNewInstanceFromClass.run();
          }
 catch (          ClassCastException e) {
            throw XMLMarshalException.unmappedContentHandlerDoesntImplement(e,unmappedContentHandlerClass.getName());
          }
catch (          IllegalAccessException e) {
            throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e,unmappedContentHandlerClass.getName());
          }
catch (          InstantiationException e) {
            throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e,unmappedContentHandlerClass.getName());
          }
          UnmappedContentHandlerWrapper unmappedContentHandlerWrapper=new UnmappedContentHandlerWrapper(unmappedContentHandler,this);
          unmappedContentHandler.setUnmarshalRecord(unmappedContentHandlerWrapper);
          unmappedContentHandler.startElement(namespaceURI,localName,qName,atts);
          xmlReader.setContentHandler(unmappedContentHandler);
          setObject(unmappedContentHandlerWrapper.getCurrentObject());
          return;
        }
      }
    }
    session=xmlContext.getReadSession(xmlDescriptor);
    UnmarshalRecord unmarshalRecord;
    if (isPrimitiveType) {
      unmarshalRecord=new XMLRootRecord(primitiveWrapperClass);
      unmarshalRecord.setSession((AbstractSession)unmarshaller.getXMLContext().getSession(0));
      unmarshalRecord.setXMLReader(this.getXMLReader());
    }
 else     if (xmlDescriptor.hasInheritance()) {
      unmarshalRecord=new UnmarshalRecord(null);
      unmarshalRecord.setUnmarshaller(unmarshaller);
      unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
      unmarshalRecord.setXMLReader(this.getXMLReader());
      unmarshalRecord.setAttributes(atts);
      Class classValue=xmlDescriptor.getInheritancePolicy().classFromRow(unmarshalRecord,session);
      if (classValue == null) {
        QName leafElementType=xmlDescriptor.getDefaultRootElementType();
        if (leafElementType != null) {
          Object indicator=xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
          if (indicator != null) {
            classValue=(Class)indicator;
          }
        }
      }
      if (classValue != null) {
        xmlDescriptor=(XMLDescriptor)session.getDescriptor(classValue);
      }
 else {
        if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
          throw DescriptorException.missingClassIndicatorField(unmarshalRecord,xmlDescriptor.getInheritancePolicy().getDescriptor());
        }
      }
      unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
    }
 else {
      unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
      unmarshalRecord.setXMLReader(this.getXMLReader());
    }
    this.descriptor=xmlDescriptor;
    this.rootRecord=unmarshalRecord;
    if (locator != null) {
      unmarshalRecord.setDocumentLocator(locator);
    }
    unmarshalRecord.setUnmarshaller(this.unmarshaller);
    unmarshalRecord.setXMLReader(this.getXMLReader());
    unmarshalRecord.setAttributes(atts);
    if (atts != null && null != atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_NIL_ATTRIBUTE)) {
      unmarshalRecord.setNil(true);
    }
    unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
    unmarshalRecord.startDocument();
    unmarshalRecord.initializeRecord(null);
    xmlReader.setContentHandler(unmarshalRecord);
    xmlReader.setLexicalHandler(unmarshalRecord);
    unmarshalRecord.startElement(namespaceURI,localName,qName,atts);
  }
 catch (  EclipseLinkException e) {
    if (null == xmlReader.getErrorHandler()) {
      throw e;
    }
 else {
      SAXParseException saxParseException=new SAXParseException(null,null,null,0,0,e);
      xmlReader.getErrorHandler().error(saxParseException);
    }
  }
}

Fixed version (ground truth):
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  try {
    XMLDescriptor xmlDescriptor=null;
    boolean isPrimitiveType=false;
    Class primitiveWrapperClass=null;
    String type=null;
    if (xmlReader.isNamespaceAware()) {
      type=atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
    }
 else {
      type=atts.getValue(XMLConstants.EMPTY_STRING,XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
    }
    if (null != type) {
      XPathFragment typeFragment=new XPathFragment(type,xmlReader.namespaceSeparator,xmlReader.isNamespaceAware());
      if (xmlReader.isNamespaceAware() && null != unmarshalNamespaceResolver) {
        typeFragment.setNamespaceURI(unmarshalNamespaceResolver.getNamespaceURI(typeFragment.getPrefix()));
      }
      xmlDescriptor=xmlContext.getDescriptorByGlobalType(typeFragment);
      if (xmlDescriptor == null) {
        QName lookupQName=null;
        if (typeFragment.getNamespaceURI() == null) {
          lookupQName=new QName(XMLConstants.SCHEMA_URL,typeFragment.getLocalName());
        }
 else {
          lookupQName=new QName(typeFragment.getNamespaceURI(),typeFragment.getLocalName());
        }
        primitiveWrapperClass=(Class)XMLConversionManager.getDefaultXMLTypes().get(lookupQName);
      }
    }
    if (xmlDescriptor == null) {
      String name;
      if (localName == null || localName.length() == 0) {
        name=qName;
      }
 else {
        name=localName;
      }
      XPathQName rootQName;
      if (namespaceURI == null || namespaceURI.length() == 0) {
        rootQName=new XPathQName(name,xmlReader.isNamespaceAware());
      }
 else {
        rootQName=new XPathQName(namespaceURI,name,xmlReader.isNamespaceAware());
      }
      xmlDescriptor=xmlContext.getDescriptor(rootQName);
      if (null == xmlDescriptor) {
        Object obj=this.xmlReader.getCurrentObject(session,null);
        if (obj != null) {
          xmlDescriptor=(XMLDescriptor)xmlContext.getSession(obj.getClass()).getDescriptor(obj.getClass());
        }
        if (xmlDescriptor == null) {
          isPrimitiveType=primitiveWrapperClass != null;
        }
      }
      if (null == xmlDescriptor && !isPrimitiveType) {
        if (this.keepAsElementPolicy != UnmarshalKeepAsElementPolicy.KEEP_NONE_AS_ELEMENT) {
          this.documentBuilder=new SAXDocumentBuilder();
          documentBuilder.startDocument();
          for (          String prefix : this.unmarshalNamespaceResolver.getPrefixes()) {
            documentBuilder.startPrefixMapping(prefix,this.unmarshalNamespaceResolver.getNamespaceURI(prefix));
          }
          documentBuilder.startElement(namespaceURI,localName,qName,atts);
          this.xmlReader.setContentHandler(documentBuilder);
          return;
        }
        Class unmappedContentHandlerClass=unmarshaller.getUnmappedContentHandlerClass();
        if (null == unmappedContentHandlerClass) {
          throw XMLMarshalException.noDescriptorWithMatchingRootElement(rootQName.toString());
        }
 else {
          UnmappedContentHandler unmappedContentHandler;
          try {
            PrivilegedNewInstanceFromClass privilegedNewInstanceFromClass=new PrivilegedNewInstanceFromClass(unmappedContentHandlerClass);
            unmappedContentHandler=(UnmappedContentHandler)privilegedNewInstanceFromClass.run();
          }
 catch (          ClassCastException e) {
            throw XMLMarshalException.unmappedContentHandlerDoesntImplement(e,unmappedContentHandlerClass.getName());
          }
catch (          IllegalAccessException e) {
            throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e,unmappedContentHandlerClass.getName());
          }
catch (          InstantiationException e) {
            throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e,unmappedContentHandlerClass.getName());
          }
          UnmappedContentHandlerWrapper unmappedContentHandlerWrapper=new UnmappedContentHandlerWrapper(unmappedContentHandler,this);
          unmappedContentHandler.setUnmarshalRecord(unmappedContentHandlerWrapper);
          unmappedContentHandler.startElement(namespaceURI,localName,qName,atts);
          xmlReader.setContentHandler(unmappedContentHandler);
          setObject(unmappedContentHandlerWrapper.getCurrentObject());
          return;
        }
      }
    }
    session=xmlContext.getReadSession(xmlDescriptor);
    UnmarshalRecord unmarshalRecord;
    if (isPrimitiveType) {
      unmarshalRecord=new XMLRootRecord(primitiveWrapperClass);
      unmarshalRecord.setSession((AbstractSession)unmarshaller.getXMLContext().getSession(0));
      unmarshalRecord.setXMLReader(this.getXMLReader());
    }
 else     if (xmlDescriptor.hasInheritance()) {
      unmarshalRecord=new UnmarshalRecord(null);
      unmarshalRecord.setUnmarshaller(unmarshaller);
      unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
      unmarshalRecord.setXMLReader(this.getXMLReader());
      unmarshalRecord.setAttributes(atts);
      Class classValue=xmlDescriptor.getInheritancePolicy().classFromRow(unmarshalRecord,session);
      if (classValue == null) {
        QName leafElementType=xmlDescriptor.getDefaultRootElementType();
        if (leafElementType != null) {
          Object indicator=xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
          if (indicator != null) {
            classValue=(Class)indicator;
          }
        }
      }
      if (classValue != null) {
        xmlDescriptor=(XMLDescriptor)session.getDescriptor(classValue);
      }
 else {
        if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
          throw DescriptorException.missingClassIndicatorField(unmarshalRecord,xmlDescriptor.getInheritancePolicy().getDescriptor());
        }
      }
      unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
    }
 else {
      unmarshalRecord=(UnmarshalRecord)xmlDescriptor.getObjectBuilder().createRecord(session);
      unmarshalRecord.setXMLReader(this.getXMLReader());
    }
    this.descriptor=xmlDescriptor;
    this.rootRecord=unmarshalRecord;
    if (locator != null) {
      unmarshalRecord.setDocumentLocator(locator);
    }
    unmarshalRecord.setUnmarshaller(this.unmarshaller);
    unmarshalRecord.setXMLReader(this.getXMLReader());
    unmarshalRecord.setAttributes(atts);
    if (atts != null && null != atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_NIL_ATTRIBUTE)) {
      unmarshalRecord.setNil(true);
    }
    unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
    unmarshalRecord.startDocument();
    unmarshalRecord.initializeRecord(null);
    xmlReader.setContentHandler(unmarshalRecord);
    xmlReader.setLexicalHandler(unmarshalRecord);
    unmarshalRecord.startElement(namespaceURI,localName,qName,atts);
  }
 catch (  EclipseLinkException e) {
    if (null == xmlReader.getErrorHandler()) {
      throw e;
    }
 else {
      SAXParseException saxParseException=new SAXParseException(null,null,null,0,0,e);
      xmlReader.getErrorHandler().error(saxParseException);
    }
  }
}