Program: 63607
Project: 63607
Buggy source:
public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  try {
    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());
    }
    Class primitiveWrapperClass=null;
    Descriptor xmlDescriptor=xmlContext.getDescriptor(rootQName);
    if (xmlDescriptor == null) {
      boolean isPrimitiveType=false;
      String type=null;
      if (xmlReader.isNamespaceAware()) {
        type=atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,Constants.SCHEMA_TYPE_ATTRIBUTE);
      }
 else {
        type=atts.getValue(Constants.EMPTY_STRING,Constants.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()));
        }
        Descriptor lookupDescriptor=xmlContext.getDescriptorByGlobalType(typeFragment);
        if (lookupDescriptor == null) {
          QName lookupQName=null;
          if (typeFragment.getNamespaceURI() == null) {
            lookupQName=new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI,typeFragment.getLocalName());
          }
 else {
            lookupQName=new QName(typeFragment.getNamespaceURI(),typeFragment.getLocalName());
          }
          if (null == session) {
            session=(CoreAbstractSession)xmlContext.getSession();
          }
          ConversionManager conversionManager=(ConversionManager)session.getDatasourcePlatform().getConversionManager();
          primitiveWrapperClass=conversionManager.javaType(lookupQName);
        }
 else {
          xmlDescriptor=lookupDescriptor;
          session=xmlContext.getSession(xmlDescriptor);
        }
      }
    }
 else     if (xmlDescriptor.hasInheritance()) {
      session=xmlContext.getSession(xmlDescriptor);
      UnmarshalRecord tmpUnmarshalRecord=new UnmarshalRecordImpl(null);
      tmpUnmarshalRecord.setUnmarshaller(unmarshaller);
      tmpUnmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
      tmpUnmarshalRecord.setXMLReader(this.getXMLReader());
      tmpUnmarshalRecord.setAttributes(atts);
      Class classValue=xmlDescriptor.getInheritancePolicy().classFromRow(new org.eclipse.persistence.oxm.record.UnmarshalRecord(tmpUnmarshalRecord),(CoreAbstractSession)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=(Descriptor)session.getDescriptor(classValue);
        shouldWrap=false;
      }
 else {
        if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
          throw DescriptorException.missingClassIndicatorField((XMLRecord)tmpUnmarshalRecord,(org.eclipse.persistence.oxm.XMLDescriptor)xmlDescriptor.getInheritancePolicy().getDescriptor());
        }
      }
    }
 else     if (null != xmlDescriptor.getTables() && xmlDescriptor.getTables().size() == 1) {
      shouldWrap=false;
    }
    if (null == xmlDescriptor) {
      Object obj=this.xmlReader.getCurrentObject(session,null);
      if (obj != null) {
        xmlDescriptor=(Descriptor)xmlContext.getSession(obj.getClass()).getDescriptor(obj.getClass());
      }
    }
    if (null == xmlDescriptor && primitiveWrapperClass == null) {
      if (!this.keepAsElementPolicy.isKeepNoneAsElement()) {
        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.startElement(namespaceURI,localName,qName,atts);
        xmlReader.setContentHandler(unmappedContentHandler);
        setObject(unmappedContentHandlerWrapper.getCurrentObject());
        return;
      }
    }
    if (xmlDescriptor == null && primitiveWrapperClass != null) {
      session=xmlContext.getSession(xmlDescriptor);
      rootRecord=unmarshaller.createRootUnmarshalRecord(primitiveWrapperClass);
      rootRecord.setSession((CoreAbstractSession)unmarshaller.getContext().getSession());
    }
 else {
      if (session == null) {
        session=xmlContext.getSession(xmlDescriptor);
      }
      rootRecord=unmarshaller.createUnmarshalRecord(xmlDescriptor,session);
    }
    this.descriptor=xmlDescriptor;
    rootRecord.setUnmarshaller(this.unmarshaller);
    rootRecord.setXMLReader(this.getXMLReader());
    if (locator != null) {
      rootRecord.setDocumentLocator(xmlReader.getLocator());
    }
    rootRecord.setAttributes(atts);
    boolean hasNilAttribute=(atts != null && null != atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,Constants.SCHEMA_NIL_ATTRIBUTE));
    rootRecord.setNil(isNil || hasNilAttribute);
    rootRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
    rootRecord.startDocument();
    rootRecord.initializeRecord((Mapping)null);
    xmlReader.setContentHandler(rootRecord);
    xmlReader.setLexicalHandler(rootRecord);
    Object attributeGroup=this.unmarshaller.getUnmarshalAttributeGroup();
    if (attributeGroup != null) {
      if (attributeGroup.getClass() == CoreClassConstants.STRING) {
        CoreAttributeGroup group=descriptor.getAttributeGroup((String)attributeGroup);
        if (group != null) {
          rootRecord.setUnmarshalAttributeGroup(group);
        }
 else {
        }
      }
 else       if (attributeGroup instanceof CoreAttributeGroup) {
        rootRecord.setUnmarshalAttributeGroup((CoreAttributeGroup)attributeGroup);
      }
 else {
      }
    }
    rootRecord.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 {
    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());
    }
    Class primitiveWrapperClass=null;
    Descriptor xmlDescriptor=xmlContext.getDescriptor(rootQName);
    if (xmlDescriptor == null) {
      boolean isPrimitiveType=false;
      String type=null;
      if (xmlReader.isNamespaceAware()) {
        type=atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,Constants.SCHEMA_TYPE_ATTRIBUTE);
      }
 else {
        type=atts.getValue(Constants.EMPTY_STRING,Constants.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()));
        }
        Descriptor lookupDescriptor=xmlContext.getDescriptorByGlobalType(typeFragment);
        if (lookupDescriptor == null) {
          QName lookupQName=null;
          if (typeFragment.getNamespaceURI() == null) {
            lookupQName=new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI,typeFragment.getLocalName());
          }
 else {
            lookupQName=new QName(typeFragment.getNamespaceURI(),typeFragment.getLocalName());
          }
          if (null == session) {
            session=(CoreAbstractSession)xmlContext.getSession();
          }
          ConversionManager conversionManager=(ConversionManager)session.getDatasourcePlatform().getConversionManager();
          primitiveWrapperClass=conversionManager.javaType(lookupQName);
        }
 else {
          xmlDescriptor=lookupDescriptor;
          session=xmlContext.getSession(xmlDescriptor);
        }
      }
    }
 else {
      if (null != xmlDescriptor.getDefaultRootElementField()) {
        String descLocalName=xmlDescriptor.getDefaultRootElementField().getXPathFragment().getLocalName();
        if (descLocalName != null && descLocalName.equals(localName)) {
          String descUri=xmlDescriptor.getDefaultRootElementField().getXPathFragment().getNamespaceURI();
          if (!xmlReader.isNamespaceAware() || (xmlReader.isNamespaceAware() && ((namespaceURI == null && descUri == null) || (namespaceURI != null && namespaceURI.length() == 0 && descUri == null) || (namespaceURI != null && namespaceURI.equals(descUri))))) {
            shouldWrap=false;
          }
        }
      }
      if (xmlDescriptor.hasInheritance()) {
        session=xmlContext.getSession(xmlDescriptor);
        UnmarshalRecord tmpUnmarshalRecord=new UnmarshalRecordImpl(null);
        tmpUnmarshalRecord.setUnmarshaller(unmarshaller);
        tmpUnmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
        tmpUnmarshalRecord.setXMLReader(this.getXMLReader());
        tmpUnmarshalRecord.setAttributes(atts);
        Class classValue=xmlDescriptor.getInheritancePolicy().classFromRow(new org.eclipse.persistence.oxm.record.UnmarshalRecord(tmpUnmarshalRecord),(CoreAbstractSession)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=(Descriptor)session.getDescriptor(classValue);
        }
 else {
          if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
            throw DescriptorException.missingClassIndicatorField((XMLRecord)tmpUnmarshalRecord,(org.eclipse.persistence.oxm.XMLDescriptor)xmlDescriptor.getInheritancePolicy().getDescriptor());
          }
        }
      }
    }
    if (null == xmlDescriptor) {
      Object obj=this.xmlReader.getCurrentObject(session,null);
      if (obj != null) {
        xmlDescriptor=(Descriptor)xmlContext.getSession(obj.getClass()).getDescriptor(obj.getClass());
      }
    }
    if (null == xmlDescriptor && primitiveWrapperClass == null) {
      if (!this.keepAsElementPolicy.isKeepNoneAsElement()) {
        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.startElement(namespaceURI,localName,qName,atts);
        xmlReader.setContentHandler(unmappedContentHandler);
        setObject(unmappedContentHandlerWrapper.getCurrentObject());
        return;
      }
    }
    if (xmlDescriptor == null && primitiveWrapperClass != null) {
      session=xmlContext.getSession(xmlDescriptor);
      rootRecord=unmarshaller.createRootUnmarshalRecord(primitiveWrapperClass);
      rootRecord.setSession((CoreAbstractSession)unmarshaller.getContext().getSession());
    }
 else {
      if (session == null) {
        session=xmlContext.getSession(xmlDescriptor);
      }
      rootRecord=unmarshaller.createUnmarshalRecord(xmlDescriptor,session);
    }
    this.descriptor=xmlDescriptor;
    rootRecord.setUnmarshaller(this.unmarshaller);
    rootRecord.setXMLReader(this.getXMLReader());
    if (locator != null) {
      rootRecord.setDocumentLocator(xmlReader.getLocator());
    }
    rootRecord.setAttributes(atts);
    boolean hasNilAttribute=(atts != null && null != atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,Constants.SCHEMA_NIL_ATTRIBUTE));
    rootRecord.setNil(isNil || hasNilAttribute);
    rootRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
    rootRecord.startDocument();
    rootRecord.initializeRecord((Mapping)null);
    xmlReader.setContentHandler(rootRecord);
    xmlReader.setLexicalHandler(rootRecord);
    Object attributeGroup=this.unmarshaller.getUnmarshalAttributeGroup();
    if (attributeGroup != null) {
      if (attributeGroup.getClass() == CoreClassConstants.STRING) {
        CoreAttributeGroup group=descriptor.getAttributeGroup((String)attributeGroup);
        if (group != null) {
          rootRecord.setUnmarshalAttributeGroup(group);
        }
 else {
        }
      }
 else       if (attributeGroup instanceof CoreAttributeGroup) {
        rootRecord.setUnmarshalAttributeGroup((CoreAttributeGroup)attributeGroup);
      }
 else {
      }
    }
    rootRecord.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);
    }
  }
}