nus-yam/ex-repair huggingface dataset:
Program: 64823
Project: 64823
Buggy source:
public AbstractRecord buildRow(AbstractRecord databaseRow,Object object,AbstractSession session,boolean wasXMLRoot){
  XMLRecord row=(XMLRecord)databaseRow;
  row.setSession(session);
  XMLMarshaller marshaller=row.getMarshaller();
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().beforeMarshal(object);
  }
  writeOutMappings(row,object,session);
  if (!getDescriptor().isAggregateDescriptor()) {
    addPrimaryKeyForNonDefaultTable(row);
  }
  addNamespaceDeclarations((row).getDocument());
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().afterMarshal(object);
  }
  return row;
}

Fixed version (ground truth):
public AbstractRecord buildRow(AbstractRecord databaseRow,Object object,AbstractSession session,boolean wasXMLRoot){
  XMLRecord row=(XMLRecord)databaseRow;
  row.setSession(session);
  XMLMarshaller marshaller=row.getMarshaller();
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().beforeMarshal(object);
  }
  addNamespaceDeclarations((row).getDocument());
  writeOutMappings(row,object,session);
  if (!getDescriptor().isAggregateDescriptor()) {
    addPrimaryKeyForNonDefaultTable(row);
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().afterMarshal(object);
  }
  return row;
}
Program: 64824
Project: 64824
Buggy source:
private String resolveNamespacePrefixForURI(String namespaceURI,NamespaceResolver namespaceResolver){
  if (null == namespaceResolver) {
    return null;
  }
  Enumeration prefixes=namespaceResolver.getPrefixes();
  String prefix;
  while (prefixes.hasMoreElements()) {
    prefix=(String)prefixes.nextElement();
    if (namespaceResolver.resolveNamespacePrefix(prefix).equals(namespaceURI)) {
      return prefix;
    }
  }
  return null;
}

Fixed version (ground truth):
private String resolveNamespacePrefixForURI(String namespaceURI,NamespaceResolver namespaceResolver){
  if (null == namespaceResolver) {
    return null;
  }
  return namespaceResolver.resolveNamespaceURI(namespaceURI);
}
Program: 64826
Project: 64826
Buggy source:
private void addXsiNilToElement(Element element,XMLField xmlField){
  NamespaceResolver nsr=new NamespaceResolver();
  nsr.setDOM(element);
  String schemaInstancePrefix=resolveNamespacePrefixForURI(XMLConstants.SCHEMA_INSTANCE_URL,nsr);
  if (schemaInstancePrefix == null) {
    nsr=getNamespaceResolverForField(xmlField);
    schemaInstancePrefix=nsr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
    if (schemaInstancePrefix == null) {
      schemaInstancePrefix=nsr.generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
    }
    element.setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + schemaInstancePrefix,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  element.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_INSTANCE_PREFIX + XMLConstants.COLON + XMLConstants.SCHEMA_NIL_ATTRIBUTE,XMLConstants.BOOLEAN_STRING_TRUE);
}

Fixed version (ground truth):
private void addXsiNilToElement(Element element,XMLField xmlField){
  NamespaceResolver nsr=new NamespaceResolver();
  nsr.setDOM(element);
  String schemaInstancePrefix=resolveNamespacePrefixForURI(XMLConstants.SCHEMA_INSTANCE_URL,nsr);
  Node parentNode=element.getParentNode();
  while (schemaInstancePrefix == null && parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
    nsr.setDOM(element);
    schemaInstancePrefix=resolveNamespacePrefixForURI(XMLConstants.SCHEMA_INSTANCE_URL,nsr);
    parentNode=parentNode.getParentNode();
  }
  if (schemaInstancePrefix == null && element.getOwnerDocument() != null) {
    nsr.setDOM(element.getOwnerDocument().getDocumentElement());
    schemaInstancePrefix=resolveNamespacePrefixForURI(XMLConstants.SCHEMA_INSTANCE_URL,nsr);
  }
  if (schemaInstancePrefix == null) {
    nsr=getNamespaceResolverForField(xmlField);
    schemaInstancePrefix=nsr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
    if (schemaInstancePrefix == null) {
      schemaInstancePrefix=nsr.generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
    }
    element.setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + schemaInstancePrefix,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  element.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_INSTANCE_PREFIX + XMLConstants.COLON + XMLConstants.SCHEMA_NIL_ATTRIBUTE,XMLConstants.BOOLEAN_STRING_TRUE);
}
Program: 64833
Project: 64833
Buggy source:
public boolean startElement(XPathFragment xPathFragment,UnmarshalRecord unmarshalRecord,Attributes atts){
  try {
    unmarshalRecord.removeNullCapableValue(this);
    XMLField xmlField=(XMLField)xmlBinaryDataMapping.getField();
    XPathFragment lastFragment=xmlField.getLastXPathFragment();
    BinaryMappingContentHandler handler=new BinaryMappingContentHandler(unmarshalRecord,this,this.xmlBinaryDataMapping);
    String qnameString=xPathFragment.getLocalName();
    if (xPathFragment.getPrefix() != null) {
      qnameString=xPathFragment.getPrefix() + XMLConstants.COLON + qnameString;
    }
    handler.startElement(xPathFragment.getNamespaceURI(),xPathFragment.getLocalName(),qnameString,atts);
    XMLReader xmlReader=unmarshalRecord.getXMLReader();
    xmlReader.setContentHandler(handler);
    xmlReader.setLexicalHandler(handler);
    return true;
  }
 catch (  SAXException ex) {
    throw XMLMarshalException.unmarshalException(ex);
  }
}

Fixed version (ground truth):
public boolean startElement(XPathFragment xPathFragment,UnmarshalRecord unmarshalRecord,Attributes atts){
  try {
    if (unmarshalRecord.isNil() && xmlBinaryDataMapping.getNullPolicy().isNullRepresentedByXsiNil()) {
      xmlBinaryDataMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(),null);
      return true;
    }
    unmarshalRecord.removeNullCapableValue(this);
    XMLField xmlField=(XMLField)xmlBinaryDataMapping.getField();
    XPathFragment lastFragment=xmlField.getLastXPathFragment();
    BinaryMappingContentHandler handler=new BinaryMappingContentHandler(unmarshalRecord,this,this.xmlBinaryDataMapping);
    String qnameString=xPathFragment.getLocalName();
    if (xPathFragment.getPrefix() != null) {
      qnameString=xPathFragment.getPrefix() + XMLConstants.COLON + qnameString;
    }
    handler.startElement(xPathFragment.getNamespaceURI(),xPathFragment.getLocalName(),qnameString,atts);
    XMLReader xmlReader=unmarshalRecord.getXMLReader();
    xmlReader.setContentHandler(handler);
    xmlReader.setLexicalHandler(handler);
    return true;
  }
 catch (  SAXException ex) {
    throw XMLMarshalException.unmarshalException(ex);
  }
}
Program: 64839
Project: 64839
Buggy source:
@Override public void writeFromObjectIntoRow(Object object,AbstractRecord row,AbstractSession session,WriteType writeType){
  Object attributeValue=getAttributeValueFromObject(object);
  if (attributeValue == null) {
    return;
  }
  writeSingleValue(attributeValue,object,(XMLRecord)row,session);
}

Fixed version (ground truth):
@Override public void writeFromObjectIntoRow(Object object,AbstractRecord row,AbstractSession session,WriteType writeType){
  Object attributeValue=getAttributeValueFromObject(object);
  if (attributeValue == null) {
    XMLField field=(XMLField)getField();
    if (getNullPolicy() != null && !field.getXPathFragment().isSelfFragment()) {
      getNullPolicy().directMarshal(this.getField(),(XMLRecord)row,object);
    }
    return;
  }
  writeSingleValue(attributeValue,object,(XMLRecord)row,session);
}
Program: 64843
Project: 64843
Buggy source:
@Override public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  if (rootElementName == null) {
    rootElementName=qName;
    rootElementLocalName=localName;
    rootElementNamespaceUri=namespaceURI;
  }
  elementCount++;
  if (elementCount > 1) {
    shouldReadChars=false;
  }
}

Fixed version (ground truth):
@Override public void startElement(String namespaceURI,String localName,String qName,Attributes atts) throws SAXException {
  if (rootElementName == null) {
    rootElementName=qName;
    rootElementLocalName=localName;
    rootElementNamespaceUri=namespaceURI;
  }
  if (XMLConstants.EMPTY_STRING.equals(localName)) {
    return;
  }
  elementCount++;
  if (elementCount > 1) {
    shouldReadChars=false;
  }
}
Program: 64844
Project: 64844
Buggy source:
/** 
 * Default constructor.
 */
public XMLRootRecord(Class cls){
  super(null);
  targetClass=cls;
  shouldReadChars=true;
  elementCount=0;
}

Fixed version (ground truth):
/** 
 * Default constructor.
 */
public XMLRootRecord(Class cls){
  super(null);
  targetClass=cls;
}
Program: 64845
Project: 64845
Buggy source:
@Override public void startDocument() throws SAXException {
}

Fixed version (ground truth):
@Override public void startDocument() throws SAXException {
  characters=null;
  elementCount=0;
  shouldReadChars=true;
}
Program: 64846
Project: 64846
Buggy source:
private void parse(XMLStreamReader xmlStreamReader) throws SAXException {
  locator=new StreamReaderLocator(xmlStreamReader);
  try {
    contentHandler.startDocument();
    parseEvent(xmlStreamReader,xmlStreamReader.getEventType());
    while (depth > 0) {
      int eventType=xmlStreamReader.next();
      parseEvent(xmlStreamReader,eventType);
    }
    contentHandler.endDocument();
  }
 catch (  SAXException e) {
    throw e;
  }
catch (  Exception e) {
    throw new SAXException(e);
  }
}

Fixed version (ground truth):
public void parse(XMLStreamReader xmlStreamReader) throws SAXException {
  unmarshalNamespaceContext.setXmlStreamReader(xmlStreamReader);
  indexedAttributeList.setXmlStreamReader(xmlStreamReader);
  locator=new StreamReaderLocator(xmlStreamReader);
  try {
    contentHandler.startDocument();
    parseEvent(xmlStreamReader,xmlStreamReader.getEventType());
    while (depth > 0) {
      int eventType=xmlStreamReader.next();
      parseEvent(xmlStreamReader,eventType);
    }
    contentHandler.endDocument();
  }
 catch (  SAXException e) {
    throw e;
  }
catch (  Exception e) {
    throw new SAXException(e);
  }
}
Program: 64847
Project: 64847
Buggy source:
public String resolveNamespacePrefix(String prefix){
  String namespaceURI=getUnmarshalNamespaceResolver().getNamespaceURI(prefix);
  if (null == namespaceURI && null != getParentRecord()) {
    namespaceURI=getParentRecord().resolveNamespacePrefix(prefix);
  }
  return namespaceURI;
}

Fixed version (ground truth):
public String resolveNamespacePrefix(String prefix){
  String namespaceURI=getUnmarshalNamespaceResolver().getNamespaceURI(prefix);
  if (null == namespaceURI && null != parentRecord) {
    namespaceURI=parentRecord.resolveNamespacePrefix(prefix);
  }
  return namespaceURI;
}
Program: 64848
Project: 64848
Buggy source:
public String resolveNamespaceUri(String uri){
  String prefix=getUnmarshalNamespaceResolver().getPrefix(uri);
  if (null == prefix) {
    if (null != getParentRecord()) {
      prefix=getParentRecord().resolveNamespaceUri(uri);
    }
  }
  return prefix;
}

Fixed version (ground truth):
public String resolveNamespaceUri(String uri){
  String prefix=getUnmarshalNamespaceResolver().getPrefix(uri);
  if (null == prefix) {
    if (null != parentRecord) {
      prefix=parentRecord.resolveNamespaceUri(uri);
    }
  }
  return prefix;
}
Program: 64849
Project: 64849
Buggy source:
public void setDocumentLocator(Locator locator){
  this.documentLocator=locator;
  if ((this.getParentRecord() == null) && locator instanceof Locator2) {
    Locator2 loc=(Locator2)locator;
    this.setEncoding(loc.getEncoding());
    this.setVersion(loc.getXMLVersion());
  }
}

Fixed version (ground truth):
public void setDocumentLocator(Locator locator){
  this.documentLocator=locator;
  if (null == rootElementName && null == rootElementLocalName && parentRecord == null && locator instanceof Locator2) {
    Locator2 loc=(Locator2)locator;
    this.setEncoding(loc.getEncoding());
    this.setVersion(loc.getXMLVersion());
  }
}
Program: 64853
Project: 64853
Buggy source:
public void startDocument() throws SAXException {
  if (unmarshaller.getIDResolver() != null && getParentRecord() == null) {
    unmarshaller.getIDResolver().startDocument(unmarshaller.getErrorHandler());
  }
}

Fixed version (ground truth):
public void startDocument() throws SAXException {
  if (unmarshaller.getIDResolver() != null && parentRecord == null) {
    unmarshaller.getIDResolver().startDocument(unmarshaller.getErrorHandler());
  }
}
Program: 64854
Project: 64854
Buggy source:
private static <T>T restCreate(Object object,String type,Class<T> resultClass,String persistenceUnit,Map<String,String> tenantId,MediaType inputMediaType,MediaType outputMediaType,boolean sendLinks) throws RestCallFailedException {
  StringBuffer uri=new StringBuffer();
  uri.append(getServerURI() + persistenceUnit);
  if (tenantId != null) {
    for (    String key : tenantId.keySet()) {
      uri.append("String_Node_Str" + key + "String_Node_Str"+ tenantId.get(key));
    }
  }
  uri.append("String_Node_Str" + type);
  WebResource webResource=client.resource(uri.toString());
  ByteArrayOutputStream os=new ByteArrayOutputStream();
  try {
    if (sendLinks) {
      context.marshallEntity(object,inputMediaType,os);
    }
 else {
      context.marshallEntity(object,inputMediaType,os,false);
    }
  }
 catch (  JAXBException e) {
    fail("String_Node_Str" + e);
  }
  ClientResponse response=webResource.type(inputMediaType).accept(outputMediaType).put(ClientResponse.class,os.toString());
  Status status=response.getClientResponseStatus();
  if (status != Status.CREATED) {
    throw new RestCallFailedException(status);
  }
  String result=response.getEntity(String.class);
  T resultObject=null;
  try {
    resultObject=(T)context.unmarshalEntity(type,outputMediaType,new ByteArrayInputStream(result.getBytes()));
  }
 catch (  JAXBException e) {
    fail("String_Node_Str" + e);
  }
  return resultObject;
}

Fixed version (ground truth):
private static <T>T restCreate(Object object,String type,Class<T> resultClass,String persistenceUnit,Map<String,String> tenantId,MediaType inputMediaType,MediaType outputMediaType) throws RestCallFailedException {
  StringBuffer uri=new StringBuffer();
  uri.append(getServerURI() + persistenceUnit);
  if (tenantId != null) {
    for (    String key : tenantId.keySet()) {
      uri.append("String_Node_Str" + key + "String_Node_Str"+ tenantId.get(key));
    }
  }
  uri.append("String_Node_Str" + type);
  WebResource webResource=client.resource(uri.toString());
  ByteArrayOutputStream os=new ByteArrayOutputStream();
  try {
    context.marshallEntity(object,inputMediaType,os,false);
  }
 catch (  JAXBException e) {
    fail("String_Node_Str" + e);
  }
  ClientResponse response=webResource.type(inputMediaType).accept(outputMediaType).put(ClientResponse.class,os.toString());
  Status status=response.getClientResponseStatus();
  if (status != Status.CREATED) {
    throw new RestCallFailedException(status);
  }
  String result=response.getEntity(String.class);
  T resultObject=null;
  try {
    resultObject=(T)context.unmarshalEntity(type,outputMediaType,new ByteArrayInputStream(result.getBytes()));
  }
 catch (  JAXBException e) {
    fail("String_Node_Str" + e);
  }
  return resultObject;
}
Program: 64856
Project: 64856
Buggy source:
@Test public void testCreateXML(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(101);
  user=restCreate(user,"String_Node_Str",StaticUser.class,DEFAULT_PU,null,MediaType.APPLICATION_XML_TYPE,MediaType.APPLICATION_XML_TYPE,true);
  assertTrue("String_Node_Str",user.getName().equals("String_Node_Str"));
  StaticUser dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",user.equals(dbUser));
  restDelete(user.getId(),"String_Node_Str",StaticUser.class);
  dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",dbUser == null);
}

Fixed version (ground truth):
@Test public void testCreateXML(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(101);
  user=restCreate(user,"String_Node_Str",StaticUser.class,DEFAULT_PU,null,MediaType.APPLICATION_XML_TYPE,MediaType.APPLICATION_XML_TYPE);
  assertTrue("String_Node_Str",user.getName().equals("String_Node_Str"));
  StaticUser dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",user.equals(dbUser));
  restDelete(user.getId(),"String_Node_Str",StaticUser.class);
  dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",dbUser == null);
}
Program: 64858
Project: 64858
Buggy source:
@Test(expected=RestCallFailedException.class) public void testCreateNonExistantPersistenceUnit(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(103);
  user=restCreate(user,"String_Node_Str",StaticUser.class,"String_Node_Str",null,MediaType.APPLICATION_XML_TYPE,MediaType.APPLICATION_XML_TYPE,true);
}

Fixed version (ground truth):
@Test(expected=RestCallFailedException.class) public void testCreateNonExistantPersistenceUnit(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(103);
  user=restCreate(user,"String_Node_Str",StaticUser.class,"String_Node_Str",null,MediaType.APPLICATION_XML_TYPE,MediaType.APPLICATION_XML_TYPE);
}
Program: 64859
Project: 64859
Buggy source:
@Test(expected=RestCallFailedException.class) public void testCreateSequenced(){
  StaticAuction auction=new StaticAuction();
  auction.setName("String_Node_Str");
  auction=restCreate(auction,"String_Node_Str",StaticAuction.class,true);
}

Fixed version (ground truth):
@Test(expected=RestCallFailedException.class) public void testCreateSequenced(){
  StaticAuction auction=new StaticAuction();
  auction.setName("String_Node_Str");
  auction=restCreate(auction,"String_Node_Str",StaticAuction.class);
}
Program: 64860
Project: 64860
Buggy source:
@AfterClass public static void teardown(){
}

Fixed version (ground truth):
@AfterClass public static void teardown(){
  StaticModelDatabasePopulator.cleanupDB(context.getEmf());
}
Program: 64861
Project: 64861
Buggy source:
@Test(expected=RestCallFailedException.class) public void testCreateNonExistant(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(102);
  user=restCreate(user,"String_Node_Str",StaticUser.class,true);
}

Fixed version (ground truth):
@Test(expected=RestCallFailedException.class) public void testCreateNonExistant(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(102);
  user=restCreate(user,"String_Node_Str",StaticUser.class);
}
Program: 64862
Project: 64862
Buggy source:
@Test public void testCreateDelete(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(100);
  user=restCreate(user,"String_Node_Str",StaticUser.class,true);
  assertTrue("String_Node_Str",user.getName().equals("String_Node_Str"));
  StaticUser dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",user.equals(dbUser));
  restDelete(user.getId(),"String_Node_Str",StaticUser.class);
  dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",dbUser == null);
}

Fixed version (ground truth):
@Test public void testCreateDelete(){
  StaticUser user=new StaticUser();
  user.setName("String_Node_Str");
  user.setId(100);
  user=restCreate(user,"String_Node_Str",StaticUser.class);
  assertTrue("String_Node_Str",user.getName().equals("String_Node_Str"));
  StaticUser dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",user.equals(dbUser));
  restDelete(user.getId(),"String_Node_Str",StaticUser.class);
  dbUser=dbRead(user.getId(),StaticUser.class);
  assertTrue("String_Node_Str",dbUser == null);
}
Program: 64863
Project: 64863
Buggy source:
@BeforeClass public static void setup() throws URISyntaxException {
  Map<String,Object> properties=new HashMap<String,Object>();
  ExamplePropertiesLoader.loadProperties(properties);
  properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE,null);
  properties.put(PersistenceUnitProperties.JTA_DATASOURCE,null);
  properties.put(PersistenceUnitProperties.DDL_GENERATION,PersistenceUnitProperties.DROP_AND_CREATE);
  PersistenceFactoryBase factory=new PersistenceFactoryBase();
  EntityManagerFactory emf=Persistence.createEntityManagerFactory(DEFAULT_PU,properties);
  context=factory.bootstrapPersistenceContext("String_Node_Str",emf,new URI("String_Node_Str"),false);
  StaticModelDatabasePopulator.cleanupDB(context.getEmf());
  StaticModelDatabasePopulator.populateDB(emf);
  client=Client.create();
}

Fixed version (ground truth):
@BeforeClass public static void setup() throws URISyntaxException {
  Map<String,Object> properties=new HashMap<String,Object>();
  ExamplePropertiesLoader.loadProperties(properties);
  properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE,null);
  properties.put(PersistenceUnitProperties.JTA_DATASOURCE,null);
  properties.put(PersistenceUnitProperties.DDL_GENERATION,PersistenceUnitProperties.DROP_AND_CREATE);
  PersistenceFactoryBase factory=new PersistenceFactoryBase();
  EntityManagerFactory emf=Persistence.createEntityManagerFactory(DEFAULT_PU,properties);
  context=factory.bootstrapPersistenceContext("String_Node_Str",emf,new URI("String_Node_Str"),false);
  StaticModelDatabasePopulator.populateDB(emf);
  client=Client.create();
}
Program: 64864
Project: 64864
Buggy source:
@Test public void testNamedQueryHint(){
  Map<String,String> hints=new HashMap<String,String>();
  hints.put(QueryHints.REFRESH,"String_Node_Str");
  List<StaticUser> users=(List<StaticUser>)restNamedQuery("String_Node_Str","String_Node_Str",null,null);
  assertTrue("String_Node_Str",users.size() == 3);
  StaticUser user1=users.get(0);
  String oldName=user1.getName();
  user1.setName("String_Node_Str");
  dbUpdate(user1);
  users=(List<StaticUser>)restNamedQuery("String_Node_Str","String_Node_Str",null,hints);
  for (  StaticUser user : users) {
    if (user.getId() == user1.getId()) {
      assertTrue("String_Node_Str",user.getName().equals(user1.getName()));
    }
  }
  user1=dbRead(user1.getId(),StaticUser.class);
  user1.setName(oldName);
  dbUpdate(user1);
  hints=new HashMap<String,String>();
  hints.put(QueryHints.REFRESH,"String_Node_Str");
  users=(List<StaticUser>)restNamedQuery("String_Node_Str","String_Node_Str",null,hints);
}

Fixed version (ground truth):
@Test public void testNamedQueryHint(){
  Map<String,String> hints=new HashMap<String,String>();
  hints.put(QueryHints.REFRESH,"String_Node_Str");
  List<StaticUser> users=(List<StaticUser>)restNamedQuery("String_Node_Str","String_Node_Str",null,hints);
  assertTrue("String_Node_Str",users.size() == 3);
  StaticUser user1=users.get(0);
  String oldName=user1.getName();
  user1.setName("String_Node_Str");
  dbUpdate(user1);
  users=(List<StaticUser>)restNamedQuery("String_Node_Str","String_Node_Str",null,hints);
  for (  StaticUser user : users) {
    if (user.getId() == user1.getId()) {
      assertTrue("String_Node_Str",user.getName().equals(user1.getName()));
    }
  }
  user1=dbRead(user1.getId(),StaticUser.class);
  user1.setName(oldName);
  dbUpdate(user1);
  hints=new HashMap<String,String>();
  hints.put(QueryHints.REFRESH,"String_Node_Str");
  users=(List<StaticUser>)restNamedQuery("String_Node_Str","String_Node_Str",null,hints);
}
Program: 64866
Project: 64866
Buggy source:
private boolean isRelationshipRepresentedInRelationshipInfo(String relationship,PersistenceWeavedRest object){
  for (  RelationshipInfo info : object._persistence_getRelationships()) {
    if (info.getAttributeName().equals(relationship)) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Check to see if our weaved list of relationships contains a particular attribute. This will tell us if an object that has been composed by unmarshalling XML or JSON has had that relationship fetched.  When the relationship is present in the list of RelationShipInfo objects, it means it is not fetched.
 * @param relationship
 * @param object
 * @return
 */
private boolean isRelationshipRepresentedInRelationshipInfo(String relationship,PersistenceWeavedRest object){
  for (  RelationshipInfo info : object._persistence_getRelationships()) {
    if (info.getAttributeName().equals(relationship)) {
      return true;
    }
  }
  return false;
}
Program: 64867
Project: 64867
Buggy source:
protected void preMarshallEntity(Object object){
  if (object instanceof List) {
    Iterator i=((List)object).iterator();
    while (i.hasNext()) {
      preMarshallIndividualEntity(i.next());
    }
  }
 else {
    preMarshallIndividualEntity(object);
  }
}

Fixed version (ground truth):
/** 
 * Process an entity and add any additional data that needs to be added prior to marshalling This method will both single entities and lists of entities
 * @param object
 */
protected void preMarshallEntity(Object object){
  if (object instanceof List) {
    Iterator i=((List)object).iterator();
    while (i.hasNext()) {
      preMarshallIndividualEntity(i.next());
    }
  }
 else {
    preMarshallIndividualEntity(object);
  }
}
Program: 64868
Project: 64868
Buggy source:
protected Object wrap(Object entity){
  ClassDescriptor descriptor=getJpaSession().getDescriptor(entity);
  if (entity instanceof FetchGroupTracker && entity instanceof PersistenceWeavedRest) {
    FetchGroup fetchGroup=new FetchGroup();
    for (    DatabaseMapping mapping : descriptor.getMappings()) {
      if (!mapping.isForeignReferenceMapping() || mapping.isPrivateOwned() || !isRelationshipRepresentedInRelationshipInfo(mapping.getAttributeName(),(PersistenceWeavedRest)entity)) {
        fetchGroup.addAttribute(mapping.getAttributeName());
      }
    }
    (new FetchGroupManager()).setObjectFetchGroup(entity,fetchGroup,null);
  }
 else   if (descriptor.hasRelationships()) {
    for (    DatabaseMapping mapping : descriptor.getMappings()) {
      if (isRelationshipRepresentedInRelationshipInfo(mapping.getAttributeName(),(PersistenceWeavedRest)entity)) {
        throw new JPARSException(LoggingLocalization.buildMessage("String_Node_Str",new Object[]{}));
      }
    }
  }
  return entity;
}

Fixed version (ground truth):
/** 
 * Make adjustements to an unmarshalled entity based on what is found in the weaved fields
 * @param entity
 * @return
 */
protected Object wrap(Object entity){
  ClassDescriptor descriptor=getJpaSession().getDescriptor(entity);
  if (entity instanceof FetchGroupTracker && entity instanceof PersistenceWeavedRest) {
    FetchGroup fetchGroup=new FetchGroup();
    for (    DatabaseMapping mapping : descriptor.getMappings()) {
      if (!mapping.isForeignReferenceMapping() || mapping.isPrivateOwned() || !isRelationshipRepresentedInRelationshipInfo(mapping.getAttributeName(),(PersistenceWeavedRest)entity)) {
        fetchGroup.addAttribute(mapping.getAttributeName());
      }
    }
    (new FetchGroupManager()).setObjectFetchGroup(entity,fetchGroup,null);
  }
 else   if (descriptor.hasRelationships()) {
    for (    DatabaseMapping mapping : descriptor.getMappings()) {
      if (isRelationshipRepresentedInRelationshipInfo(mapping.getAttributeName(),(PersistenceWeavedRest)entity)) {
        throw new JPARSException(LoggingLocalization.buildMessage("String_Node_Str",new Object[]{}));
      }
    }
  }
  return entity;
}
Program: 64869
Project: 64869
Buggy source:
protected void preMarshallIndividualEntity(Object entity){
  if (entity instanceof PersistenceWeavedRest) {
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(entity.getClass());
    if (descriptor != null) {
      ((PersistenceWeavedRest)entity)._persistence_setRelationships(new ArrayList<RelationshipInfo>());
      for (      DatabaseMapping mapping : descriptor.getMappings()) {
        if (mapping.isForeignReferenceMapping()) {
          ForeignReferenceMapping frMapping=(ForeignReferenceMapping)mapping;
          if (!frMapping.isPrivateOwned()) {
            RelationshipInfo info=new RelationshipInfo();
            info.setAttributeName(frMapping.getAttributeName());
            info.setOwningEntity(entity);
            info.setOwningEntityAlias(descriptor.getAlias());
            info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity,getJpaSession()));
            ((PersistenceWeavedRest)entity)._persistence_getRelationships().add(info);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Add any data required prior to marshalling an entity to XML or JSON In general, this will only affect fields that have been weaved into the object
 * @param entity
 */
protected void preMarshallIndividualEntity(Object entity){
  if (entity instanceof PersistenceWeavedRest) {
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(entity.getClass());
    if (descriptor != null) {
      ((PersistenceWeavedRest)entity)._persistence_setRelationships(new ArrayList<RelationshipInfo>());
      for (      DatabaseMapping mapping : descriptor.getMappings()) {
        if (mapping.isForeignReferenceMapping()) {
          ForeignReferenceMapping frMapping=(ForeignReferenceMapping)mapping;
          if (!frMapping.isPrivateOwned()) {
            RelationshipInfo info=new RelationshipInfo();
            info.setAttributeName(frMapping.getAttributeName());
            info.setOwningEntity(entity);
            info.setOwningEntityAlias(descriptor.getAlias());
            info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity,getJpaSession()));
            ((PersistenceWeavedRest)entity)._persistence_getRelationships().add(info);
          }
        }
      }
    }
  }
}
Program: 64870
Project: 64870
Buggy source:
/** 
 * Return an XMLGregorianCalander created with a given date string
 * @param dateString
 * @return
 */
public XMLGregorianCalendar convertStringToXMLGregorianCalendar(String sourceString){
  String trimmedSourceString=sourceString.trim();
  XMLGregorianCalendar calToReturn=null;
  try {
    calToReturn=getDatatypeFactory().newXMLGregorianCalendar(trimmedSourceString);
  }
 catch (  IllegalArgumentException e1) {
    try {
      int length=trimmedSourceString.length();
      String retryString=null;
      if (length >= 6 && (trimmedSourceString.charAt(4) == '-') && (trimmedSourceString.charAt(5) == '-')) {
        retryString=new StringBuilder(trimmedSourceString.substring(0,4)).append(length > 6 ? trimmedSourceString.substring(6) : "String_Node_Str").toString();
      }
 else       if (length >= 4) {
        retryString=new StringBuilder(trimmedSourceString.substring(0,4)).append("String_Node_Str").append(length > 4 ? trimmedSourceString.substring(4) : "String_Node_Str").toString();
      }
      if (retryString != null) {
        calToReturn=getDatatypeFactory().newXMLGregorianCalendar(retryString);
      }
 else {
        throw e1;
      }
    }
 catch (    IllegalArgumentException e2) {
      throw e1;
    }
  }
  return calToReturn;
}

Fixed version (ground truth):
/** 
 * Return an XMLGregorianCalander created with a given date string
 * @param dateString
 * @return
 */
public XMLGregorianCalendar convertStringToXMLGregorianCalendar(String sourceString){
  String trimmedSourceString=sourceString.trim();
  if (trimmedSourceString.length() == 0) {
    return null;
  }
  XMLGregorianCalendar calToReturn=null;
  try {
    calToReturn=getDatatypeFactory().newXMLGregorianCalendar(trimmedSourceString);
  }
 catch (  IllegalArgumentException e1) {
    try {
      int length=trimmedSourceString.length();
      String retryString=null;
      if (length >= 6 && (trimmedSourceString.charAt(4) == '-') && (trimmedSourceString.charAt(5) == '-')) {
        retryString=new StringBuilder(trimmedSourceString.substring(0,4)).append(length > 6 ? trimmedSourceString.substring(6) : "String_Node_Str").toString();
      }
 else       if (length >= 4) {
        retryString=new StringBuilder(trimmedSourceString.substring(0,4)).append("String_Node_Str").append(length > 4 ? trimmedSourceString.substring(4) : "String_Node_Str").toString();
      }
      if (retryString != null) {
        calToReturn=getDatatypeFactory().newXMLGregorianCalendar(retryString);
      }
 else {
        throw e1;
      }
    }
 catch (    IllegalArgumentException e2) {
      throw e1;
    }
  }
  return calToReturn;
}
Program: 64871
Project: 64871
Buggy source:
public void testFieldAnnotation() throws Exception {
  Marshaller marshaller=jc.createMarshaller();
  TestAttachmentMarshaller attachmentMarshaller=new TestAttachmentMarshaller();
  marshaller.setAttachmentMarshaller(attachmentMarshaller);
  FieldRoot fieldRoot=new FieldRoot();
  fieldRoot.setA("String_Node_Str".getBytes());
  fieldRoot.setB("String_Node_Str".getBytes());
  fieldRoot.setC("String_Node_Str".getBytes());
  StringWriter a=new StringWriter();
  marshaller.marshal(fieldRoot,a);
  System.out.println(a.toString());
  assertEquals(2,attachmentMarshaller.getAttachmentCount());
}

Fixed version (ground truth):
public void testFieldAnnotation() throws Exception {
  Marshaller marshaller=jc.createMarshaller();
  TestAttachmentMarshaller attachmentMarshaller=new TestAttachmentMarshaller();
  marshaller.setAttachmentMarshaller(attachmentMarshaller);
  FieldRoot fieldRoot=new FieldRoot();
  fieldRoot.setA("String_Node_Str".getBytes());
  fieldRoot.setB("String_Node_Str".getBytes());
  fieldRoot.setC("String_Node_Str".getBytes());
  StringWriter a=new StringWriter();
  marshaller.marshal(fieldRoot,a);
  assertEquals(2,attachmentMarshaller.getAttachmentCount());
}
Program: 64873
Project: 64873
Buggy source:
public void testLoadFromSAXSource() throws Exception {
  System.out.println("String_Node_Str");
  InputStream instream=ClassLoader.getSystemResourceAsStream(resourceName);
  InputSource insource=new InputSource(instream);
  SAXSource theSource=new SAXSource(insource);
  Object testObject=xmlUnmarshaller.unmarshal(theSource);
  instream.close();
  xmlToObjectTest(testObject);
}

Fixed version (ground truth):
public void testLoadFromSAXSource() throws Exception {
  InputStream instream=ClassLoader.getSystemResourceAsStream(resourceName);
  InputSource insource=new InputSource(instream);
  SAXSource theSource=new SAXSource(insource);
  Object testObject=xmlUnmarshaller.unmarshal(theSource);
  instream.close();
  xmlToObjectTest(testObject);
}
Program: 64874
Project: 64874
Buggy source:
public void testLoadFromSAXSource() throws Exception {
  System.out.println("String_Node_Str");
  InputStream instream=ClassLoader.getSystemResourceAsStream(resourceName);
  InputSource insource=new InputSource(instream);
  SAXSource theSource=new SAXSource(insource);
  Object testObject=xmlUnmarshaller.unmarshal(theSource);
  instream.close();
  xmlToObjectTest(testObject);
}

Fixed version (ground truth):
public void testLoadFromSAXSource() throws Exception {
  InputStream instream=ClassLoader.getSystemResourceAsStream(resourceName);
  InputSource insource=new InputSource(instream);
  SAXSource theSource=new SAXSource(insource);
  Object testObject=xmlUnmarshaller.unmarshal(theSource);
  instream.close();
  xmlToObjectTest(testObject);
}
Program: 64875
Project: 64875
Buggy source:
public void testLoadFromSAXSourceWithReader() throws Exception {
  System.out.println("String_Node_Str");
  InputStream instream=ClassLoader.getSystemResourceAsStream(resourceName);
  InputSource insource=new InputSource(instream);
  SAXSource theSource=new SAXSource(insource);
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XMLReader xmlReader=factory.newSAXParser().getXMLReader();
  xmlReader.setFeature("String_Node_Str",true);
  xmlReader.setFeature("String_Node_Str",true);
  theSource.setXMLReader(xmlReader);
  Object testObject=xmlUnmarshaller.unmarshal(theSource);
  instream.close();
  xmlToObjectTest(testObject);
}

Fixed version (ground truth):
public void testLoadFromSAXSourceWithReader() throws Exception {
  InputStream instream=ClassLoader.getSystemResourceAsStream(resourceName);
  InputSource insource=new InputSource(instream);
  SAXSource theSource=new SAXSource(insource);
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XMLReader xmlReader=factory.newSAXParser().getXMLReader();
  xmlReader.setFeature("String_Node_Str",true);
  xmlReader.setFeature("String_Node_Str",true);
  theSource.setXMLReader(xmlReader);
  Object testObject=xmlUnmarshaller.unmarshal(theSource);
  instream.close();
  xmlToObjectTest(testObject);
}
Program: 64876
Project: 64876
Buggy source:
public Object updateOrAddAttribute(Map<String,String> tenantId,String entityName,Object id,Map<String,Object> properties,String attribute,Object attributeValue,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  try {
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(getClass(entityName));
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    Object object=null;
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      if (partner != null) {
        ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      transaction.beginTransaction(em);
      try {
        object=em.find(getClass(entityName),id,properties);
        if (object == null) {
          return null;
        }
        attributeValue=em.merge(attributeValue);
        setMappingValueInObject(object,attributeValue,mapping,partnerMapping);
        transaction.commitTransaction(em);
      }
 catch (      Exception e) {
        JPARSLogger.fine("String_Node_Str",new Object[]{entityName,getName(),e.toString()});
        transaction.rollbackTransaction(em);
      }
    }
 else {
      return null;
    }
    return object;
  }
  finally {
    em.close();
  }
}

Fixed version (ground truth):
public Object updateOrAddAttribute(Map<String,String> tenantId,String entityName,Object id,Map<String,Object> properties,String attribute,Object attributeValue,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  try {
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(getClass(entityName));
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    Object object=null;
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      if (partner != null) {
        ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      transaction.beginTransaction(em);
      try {
        object=em.find(getClass(entityName),id,properties);
        if (object == null) {
          return null;
        }
        attributeValue=em.merge(attributeValue);
        setMappingValueInObject(object,attributeValue,mapping,partnerMapping);
        transaction.commitTransaction(em);
      }
 catch (      Exception e) {
        JPARSLogger.fine("String_Node_Str",new Object[]{entityName,getName(),e.toString()});
        transaction.rollbackTransaction(em);
        return null;
      }
    }
 else {
      return null;
    }
    return object;
  }
  finally {
    em.close();
  }
}
Program: 64877
Project: 64877
Buggy source:
public Object removeAttribute(Map<String,String> tenantId,String entityName,Object id,Map<String,Object> properties,String attribute,Object attributeValue,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  try {
    Object object=em.find(getClass(entityName),id,properties);
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(getClass(entityName));
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      if (partner != null) {
        ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      transaction.beginTransaction(em);
      try {
        attributeValue=em.merge(attributeValue);
        removeMappingValueFromObject(object,attributeValue,mapping,partnerMapping);
        transaction.commitTransaction(em);
      }
 catch (      Exception e) {
        transaction.rollbackTransaction(em);
      }
    }
 else {
      return null;
    }
    return object;
  }
  finally {
    em.close();
  }
}

Fixed version (ground truth):
public Object removeAttribute(Map<String,String> tenantId,String entityName,Object id,Map<String,Object> properties,String attribute,Object attributeValue,String partner){
  EntityManager em=getEmf().createEntityManager(tenantId);
  try {
    Object object=em.find(getClass(entityName),id,properties);
    ClassDescriptor descriptor=getJpaSession().getClassDescriptor(getClass(entityName));
    DatabaseMapping mapping=descriptor.getMappingForAttributeName(attribute);
    if (mapping == null) {
      return null;
    }
 else     if (mapping.isObjectReferenceMapping() || mapping.isCollectionMapping()) {
      DatabaseMapping partnerMapping=null;
      if (partner != null) {
        ClassDescriptor referenceDescriptor=((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        partnerMapping=referenceDescriptor.getMappingForAttributeName(partner);
        if (partnerMapping == null) {
          return null;
        }
      }
      transaction.beginTransaction(em);
      try {
        attributeValue=em.merge(attributeValue);
        removeMappingValueFromObject(object,attributeValue,mapping,partnerMapping);
        transaction.commitTransaction(em);
      }
 catch (      Exception e) {
        transaction.rollbackTransaction(em);
        return null;
      }
    }
 else {
      return null;
    }
    return object;
  }
  finally {
    em.close();
  }
}
Program: 64879
Project: 64879
Buggy source:
@AfterClass public static void tearDown(){
  String ddlDrop=System.getProperty(DATABASE_DDL_DROP_KEY,DEFAULT_DATABASE_DDL_DROP);
  if ("String_Node_Str".equalsIgnoreCase(ddlDrop)) {
    runDdl(conn,DROP_PACKAGE2_PACKAGE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_TAB1_TYPE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_TAB2_TYPE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_ORECORD_TYPE,ddlDebug);
  }
}

Fixed version (ground truth):
@AfterClass public static void tearDown(){
  String ddlDrop=System.getProperty(DATABASE_DDL_DROP_KEY,DEFAULT_DATABASE_DDL_DROP);
  if ("String_Node_Str".equalsIgnoreCase(ddlDrop)) {
    runDdl(conn,DROP_PACKAGE2_PACKAGE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_TAB1_TYPE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_TAB2_TYPE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_TAB3_TYPE,ddlDebug);
    runDdl(conn,DROP_PACKAGE2_ORECORD_TYPE,ddlDebug);
  }
}
Program: 64880
Project: 64880
Buggy source:
protected void addTypeAttribute(MarshalRecord marshalRecord,String typeValue){
  String xsiPrefix=null;
  if (marshalRecord.getNamespaceResolver() != null) {
    xsiPrefix=marshalRecord.getNamespaceResolver().resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
  }
 else {
    xsiPrefix=XMLConstants.SCHEMA_INSTANCE_PREFIX;
    marshalRecord.namespaceDeclaration(xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  if (xsiPrefix == null) {
    xsiPrefix=marshalRecord.getNamespaceResolver().generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
    marshalRecord.namespaceDeclaration(xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE,xsiPrefix + XMLConstants.COLON + XMLConstants.SCHEMA_TYPE_ATTRIBUTE,typeValue);
}

Fixed version (ground truth):
protected void addTypeAttribute(MarshalRecord marshalRecord,String typeValue){
  String xsiPrefix=null;
  if (marshalRecord.getNamespaceResolver() != null) {
    xsiPrefix=marshalRecord.getNamespaceResolver().resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
  }
 else {
    xsiPrefix=XMLConstants.SCHEMA_INSTANCE_PREFIX;
    marshalRecord.namespaceDeclaration(xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  if (xsiPrefix == null) {
    xsiPrefix=marshalRecord.getNamespaceResolver().generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
    marshalRecord.namespaceDeclaration(xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  marshalRecord.attributeWithoutQName(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE,xsiPrefix,typeValue);
}
Program: 64883
Project: 64883
Buggy source:
protected void writeXsiTypeAttribute(XMLRecord row,String typeValue,boolean addToNamespaceResolver){
  XMLField xmlField=null;
  if (row.isNamespaceAware()) {
    String xsiPrefix=null;
    boolean generated=false;
    xsiPrefix=row.getNamespaceResolver().resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
    if (xsiPrefix == null) {
      xsiPrefix=XMLConstants.SCHEMA_INSTANCE_PREFIX;
      generated=true;
      writeNamespace(row,xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL,addToNamespaceResolver);
    }
    xmlField=new XMLField(XMLConstants.ATTRIBUTE + xsiPrefix + XMLConstants.COLON+ XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
    if (generated) {
      xmlField.getLastXPathFragment().setGeneratedPrefix(true);
    }
  }
 else {
    xmlField=new XMLField(XMLConstants.ATTRIBUTE + XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
  }
  xmlField.getLastXPathFragment().setNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
  row.add(xmlField,typeValue);
}

Fixed version (ground truth):
protected void writeXsiTypeAttribute(XMLDescriptor xmlDescriptor,XMLRecord row,String typeUri,String typeLocal,String typePrefix,boolean addToNamespaceResolver){
  if (typeLocal == null) {
    return;
  }
  String typeValue=typeLocal;
  if (row.isNamespaceAware() && typeUri != null && !typeUri.equals(XMLConstants.EMPTY_STRING) && !typeUri.equals(row.getNamespaceResolver().getDefaultNamespaceURI())) {
    String prefix=row.getNamespaceResolver().resolveNamespaceURI(typeUri);
    if (prefix != null && !prefix.equals(XMLConstants.EMPTY_STRING)) {
      typeValue=prefix + row.getNamespaceSeparator() + typeValue;
    }
 else     if (typeUri.equals(XMLConstants.SCHEMA_URL)) {
      prefix=row.getNamespaceResolver().generatePrefix(XMLConstants.SCHEMA_PREFIX);
      typeValue=prefix + row.getNamespaceSeparator() + typeValue;
      row.namespaceDeclaration(prefix,typeUri);
    }
 else     if (typePrefix != null && !typePrefix.equals(XMLConstants.EMPTY_STRING)) {
      String existingUri=row.getNamespaceResolver().resolveNamespacePrefix(typePrefix);
      if (existingUri != null) {
        prefix=row.getNamespaceResolver().generatePrefix();
      }
 else {
        prefix=typePrefix;
      }
      typeValue=prefix + row.getNamespaceSeparator() + typeValue;
      row.namespaceDeclaration(prefix,typeUri);
    }
 else {
      prefix=row.getNamespaceResolver().generatePrefix();
      typeValue=prefix + row.getNamespaceSeparator() + typeValue;
      row.namespaceDeclaration(prefix,typeUri);
    }
  }
  String xsiPrefix=null;
  if (row.isNamespaceAware()) {
    NamespaceResolver nr=row.getNamespaceResolver();
    xsiPrefix=nr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
    if (xsiPrefix == null) {
      xsiPrefix=nr.generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
      row.namespaceDeclaration(xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL);
      if (addToNamespaceResolver) {
        nr.put(xsiPrefix,XMLConstants.SCHEMA_INSTANCE_URL);
      }
    }
  }
  row.attributeWithoutQName(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_TYPE_ATTRIBUTE,xsiPrefix,typeValue);
}