Program: 63387
Project: 63387
Buggy source:
public Object createSimpleXMLFormat(XRServiceAdapter xrService,Object value){
  XMLRoot xmlRoot=new XMLRoot();
  SimpleXMLFormat simpleXMLFormat=result.getSimpleXMLFormat();
  String tempSimpleXMLFormatTag=SimpleXMLFormat.DEFAULT_SIMPLE_XML_FORMAT_TAG;
  String simpleXMLFormatTag=simpleXMLFormat.getSimpleXMLFormatTag();
  if (simpleXMLFormatTag != null && !EMPTY_STR.equals(simpleXMLFormatTag)) {
    tempSimpleXMLFormatTag=simpleXMLFormatTag;
  }
  xmlRoot.setLocalName(tempSimpleXMLFormatTag);
  String tempXMLTag=DEFAULT_SIMPLE_XML_TAG;
  String xmlTag=simpleXMLFormat.getXMLTag();
  if (xmlTag != null && !EMPTY_STR.equals(xmlTag)) {
    tempXMLTag=xmlTag;
  }
  Vector<DatabaseRecord> records=null;
  if (value instanceof ArrayList) {
    JPAQuery jpaQuery=(JPAQuery)queryHandler.getDatabaseQuery();
    List<DatabaseField> paramFlds=new ArrayList<DatabaseField>();
    DatasourceCall dsCall=(DatasourceCall)jpaQuery.getDatabaseQuery().getDatasourceCall();
    for (    Object obj : dsCall.getParameters()) {
      if (obj instanceof OutputParameterForCallableStatement) {
        paramFlds.add(((OutputParameterForCallableStatement)obj).getOutputField());
      }
 else       if (obj instanceof Object[]) {
        Object[] objArray=(Object[])obj;
        for (int i=0; i < objArray.length; i++) {
          Object o=objArray[i];
          if (o instanceof OutputParameterForCallableStatement) {
            paramFlds.add(((OutputParameterForCallableStatement)o).getOutputField());
          }
        }
      }
    }
    DatabaseRecord dr=new DatabaseRecord();
    if (paramFlds.size() > 0) {
      for (int i=0; i < ((ArrayList)value).size(); i++) {
        dr.add(paramFlds.get(i),((ArrayList)value).get(i));
      }
    }
 else {
      dr.add(new DatabaseField(RESULT_STR),((ArrayList)value).get(0));
    }
    records=new Vector<DatabaseRecord>();
    records.add(dr);
  }
 else   if (value instanceof Vector) {
    Class vectorContent=((Vector)value).firstElement().getClass();
    if (DatabaseRecord.class.isAssignableFrom(vectorContent)) {
      records=(Vector<DatabaseRecord>)value;
    }
 else {
      records=new Vector<DatabaseRecord>();
      DatabaseRecord dr=new DatabaseRecord();
      dr.add(new DatabaseField(RESULT_STR),((Vector)value).firstElement());
      records.add(dr);
    }
  }
 else {
    records=new Vector<DatabaseRecord>();
    DatabaseRecord dr=new DatabaseRecord();
    dr.add(new DatabaseField(RESULT_STR),value);
    records.add(dr);
  }
  SimpleXMLFormatModel simpleXMLFormatModel=new SimpleXMLFormatModel();
  XMLConversionManager conversionManager=(XMLConversionManager)xrService.getOXSession().getDatasourcePlatform().getConversionManager();
  for (  DatabaseRecord dr : records) {
    Element rowElement=TEMP_DOC.createElement(tempXMLTag);
    for (    DatabaseField field : dr.getFields()) {
      if (field instanceof ObjectRelationalDatabaseField) {
        ObjectRelationalDatabaseField ordtField=(ObjectRelationalDatabaseField)field;
        if (xrService.getOXSession().getDescriptor(ordtField.getType()) != null) {
          xrService.getXMLContext().createMarshaller().marshal(dr.get(field),rowElement);
          continue;
        }
      }
      Object fieldValue=dr.get(field);
      if (fieldValue != null) {
        if (fieldValue instanceof Calendar) {
          Calendar cValue=(Calendar)fieldValue;
          fieldValue=conversionManager.convertObject(cValue,STRING,DATE_TIME_QNAME);
        }
        if (fieldValue instanceof Date) {
          Date dValue=(Date)fieldValue;
          fieldValue=conversionManager.convertObject(dValue,STRING,DATE_QNAME);
        }
 else         if (fieldValue instanceof Time) {
          Time tValue=(Time)fieldValue;
          fieldValue=conversionManager.convertObject(tValue,STRING,TIME_QNAME);
        }
 else         if (fieldValue instanceof Timestamp) {
          Timestamp tsValue=(Timestamp)fieldValue;
          fieldValue=conversionManager.convertObject(tsValue,STRING,DATE_TIME_QNAME);
        }
 else         if (fieldValue instanceof Blob) {
          fieldValue=conversionManager.convertObject(fieldValue,ClassConstants.APBYTE);
        }
 else         if (fieldValue.getClass().getName().equalsIgnoreCase(ORACLESQLXML_STR)) {
          try {
            Class oracleSQLXML;
            Method getStringMethod;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
              oracleSQLXML=AccessController.doPrivileged(new PrivilegedClassForName(ORACLESQLXML_STR,true,this.getClass().getClassLoader()));
              getStringMethod=AccessController.doPrivileged(new PrivilegedGetDeclaredMethod(oracleSQLXML,GETSTRING_METHOD,new Class[]{}));
              fieldValue=AccessController.doPrivileged(new PrivilegedMethodInvoker(getStringMethod,fieldValue,new Object[]{}));
            }
 else {
              oracleSQLXML=PrivilegedAccessHelper.getClassForName(ORACLESQLXML_STR,true,this.getClass().getClassLoader());
              getStringMethod=PrivilegedAccessHelper.getDeclaredMethod(oracleSQLXML,GETSTRING_METHOD,new Class[]{});
              fieldValue=PrivilegedAccessHelper.invokeMethod(getStringMethod,fieldValue,new Object[]{});
            }
          }
 catch (          Exception x) {
          }
        }
 else         if (fieldValue.getClass().getName().equalsIgnoreCase(ORACLEOPAQUE_STR)) {
          try {
            Class oracleOPAQUE;
            Class xmlTypeFactoryClass;
            Constructor xmlTypeFactoryConstructor;
            Object xmlTypeFactory;
            Method getStringMethod;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
              oracleOPAQUE=AccessController.doPrivileged(new PrivilegedClassForName(ORACLEOPAQUE_STR,true,this.getClass().getClassLoader()));
              xmlTypeFactoryClass=AccessController.doPrivileged(new PrivilegedClassForName(XMLTYPEFACTORY_STR,true,this.getClass().getClassLoader()));
              xmlTypeFactoryConstructor=AccessController.doPrivileged(new PrivilegedGetConstructorFor(xmlTypeFactoryClass,new Class[0],true));
              xmlTypeFactory=AccessController.doPrivileged(new PrivilegedInvokeConstructor(xmlTypeFactoryConstructor,new Object[0]));
              getStringMethod=AccessController.doPrivileged(new PrivilegedGetDeclaredMethod(xmlTypeFactoryClass,GETSTRING_METHOD,new Class[]{oracleOPAQUE}));
              fieldValue=AccessController.doPrivileged(new PrivilegedMethodInvoker(getStringMethod,fieldValue,new Object[]{}));
            }
 else {
              oracleOPAQUE=PrivilegedAccessHelper.getClassForName(ORACLEOPAQUE_STR,false,this.getClass().getClassLoader());
              xmlTypeFactoryClass=PrivilegedAccessHelper.getClassForName(XMLTYPEFACTORY_STR,true,this.getClass().getClassLoader());
              xmlTypeFactoryConstructor=PrivilegedAccessHelper.getConstructorFor(xmlTypeFactoryClass,new Class[0],true);
              xmlTypeFactory=PrivilegedAccessHelper.invokeConstructor(xmlTypeFactoryConstructor,new Object[0]);
              getStringMethod=PrivilegedAccessHelper.getDeclaredMethod(xmlTypeFactoryClass,GETSTRING_METHOD,new Class[]{oracleOPAQUE});
              fieldValue=PrivilegedAccessHelper.invokeMethod(getStringMethod,xmlTypeFactory,new Object[]{fieldValue});
            }
          }
 catch (          Exception x) {
          }
        }
        String elementName;
        if (field.getName() == null || (elementName=sqlToXmlName(field.getName())).equals(EMPTY_STR)) {
          elementName=RESULT_STR;
        }
        Element columnElement=TEMP_DOC.createElement(elementName);
        rowElement.appendChild(columnElement);
        String fieldValueString=fieldValue.toString();
        if (result.getType().equals(BASE_64_BINARY_QNAME)) {
          fieldValueString=Helper.buildHexStringFromBytes(Base64.base64Encode((byte[])fieldValue));
          columnElement.setAttributeNS(XMLNS_URL,XSD_STR,SCHEMA_URL);
          columnElement.setAttributeNS(XMLNS_URL,XSI_STR,SCHEMA_INSTANCE_URL);
          columnElement.setAttributeNS(SCHEMA_INSTANCE_URL,XSITYPE_STR,BASE64_BINARY_STR);
        }
        columnElement.appendChild(TEMP_DOC.createTextNode(fieldValueString));
      }
    }
    simpleXMLFormatModel.simpleXML.add(rowElement);
  }
  xmlRoot.setObject(simpleXMLFormatModel);
  return xmlRoot;
}

Fixed version (ground truth):
public Object createSimpleXMLFormat(XRServiceAdapter xrService,Object value){
  XMLRoot xmlRoot=new XMLRoot();
  SimpleXMLFormat simpleXMLFormat=result.getSimpleXMLFormat();
  String tempSimpleXMLFormatTag=SimpleXMLFormat.DEFAULT_SIMPLE_XML_FORMAT_TAG;
  String simpleXMLFormatTag=simpleXMLFormat.getSimpleXMLFormatTag();
  if (simpleXMLFormatTag != null && !EMPTY_STR.equals(simpleXMLFormatTag)) {
    tempSimpleXMLFormatTag=simpleXMLFormatTag;
  }
  xmlRoot.setLocalName(tempSimpleXMLFormatTag);
  String tempXMLTag=DEFAULT_SIMPLE_XML_TAG;
  String xmlTag=simpleXMLFormat.getXMLTag();
  if (xmlTag != null && !EMPTY_STR.equals(xmlTag)) {
    tempXMLTag=xmlTag;
  }
  Vector<DatabaseRecord> records=null;
  if (value instanceof ArrayList) {
    JPAQuery jpaQuery=(JPAQuery)queryHandler.getDatabaseQuery();
    List<DatabaseField> paramFlds=new ArrayList<DatabaseField>();
    DatasourceCall dsCall=(DatasourceCall)jpaQuery.getDatabaseQuery().getDatasourceCall();
    for (    Object obj : dsCall.getParameters()) {
      if (obj instanceof OutputParameterForCallableStatement) {
        paramFlds.add(((OutputParameterForCallableStatement)obj).getOutputField());
      }
 else       if (obj instanceof Object[]) {
        Object[] objArray=(Object[])obj;
        for (int i=0; i < objArray.length; i++) {
          Object o=objArray[i];
          if (o instanceof OutputParameterForCallableStatement) {
            paramFlds.add(((OutputParameterForCallableStatement)o).getOutputField());
          }
        }
      }
    }
    DatabaseRecord dr=new DatabaseRecord();
    if (paramFlds.size() > 0) {
      for (int i=0; i < ((ArrayList)value).size(); i++) {
        dr.add(paramFlds.get(i),((ArrayList)value).get(i));
      }
    }
 else {
      dr.add(new DatabaseField(RESULT_STR),((ArrayList)value).get(0));
    }
    records=new Vector<DatabaseRecord>();
    records.add(dr);
  }
 else   if (value instanceof Vector) {
    Class vectorContent=((Vector)value).firstElement().getClass();
    if (DatabaseRecord.class.isAssignableFrom(vectorContent)) {
      records=(Vector<DatabaseRecord>)value;
    }
 else {
      records=new Vector<DatabaseRecord>();
      DatabaseRecord dr=new DatabaseRecord();
      dr.add(new DatabaseField(RESULT_STR),((Vector)value).firstElement());
      records.add(dr);
    }
  }
 else {
    records=new Vector<DatabaseRecord>();
    DatabaseRecord dr=new DatabaseRecord();
    dr.add(new DatabaseField(RESULT_STR),value);
    records.add(dr);
  }
  SimpleXMLFormatModel simpleXMLFormatModel=new SimpleXMLFormatModel();
  XMLConversionManager conversionManager=(XMLConversionManager)xrService.getOXSession().getDatasourcePlatform().getConversionManager();
  for (  DatabaseRecord dr : records) {
    Element rowElement=TEMP_DOC.createElement(tempXMLTag);
    for (    DatabaseField field : dr.getFields()) {
      if (field instanceof ObjectRelationalDatabaseField) {
        ObjectRelationalDatabaseField ordtField=(ObjectRelationalDatabaseField)field;
        if (xrService.getOXSession().getDescriptor(ordtField.getType()) != null) {
          xrService.getXMLContext().createMarshaller().marshal(dr.get(field),rowElement);
          continue;
        }
      }
      Object fieldValue=dr.get(field);
      if (fieldValue != null) {
        if (fieldValue instanceof Calendar) {
          Calendar cValue=(Calendar)fieldValue;
          fieldValue=conversionManager.convertObject(cValue,STRING,DATE_TIME_QNAME);
        }
        if (fieldValue instanceof Date) {
          Date dValue=(Date)fieldValue;
          fieldValue=conversionManager.convertObject(dValue,STRING,DATE_QNAME);
        }
 else         if (fieldValue instanceof Time) {
          Time tValue=(Time)fieldValue;
          fieldValue=conversionManager.convertObject(tValue,STRING,TIME_QNAME);
        }
 else         if (fieldValue instanceof Timestamp) {
          Timestamp tsValue=(Timestamp)fieldValue;
          fieldValue=conversionManager.convertObject(tsValue,STRING,DATE_TIME_QNAME);
        }
 else         if (fieldValue instanceof Blob) {
          fieldValue=conversionManager.convertObject(fieldValue,ClassConstants.APBYTE);
        }
 else         if (fieldValue.getClass().getName().equalsIgnoreCase(ORACLESQLXML_STR)) {
          try {
            Class oracleSQLXML;
            Method getStringMethod;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
              oracleSQLXML=AccessController.doPrivileged(new PrivilegedClassForName(ORACLESQLXML_STR,true,this.getClass().getClassLoader()));
              getStringMethod=AccessController.doPrivileged(new PrivilegedGetDeclaredMethod(oracleSQLXML,GETSTRING_METHOD,new Class[]{}));
              fieldValue=AccessController.doPrivileged(new PrivilegedMethodInvoker(getStringMethod,fieldValue,new Object[]{}));
            }
 else {
              oracleSQLXML=PrivilegedAccessHelper.getClassForName(ORACLESQLXML_STR,true,this.getClass().getClassLoader());
              getStringMethod=PrivilegedAccessHelper.getDeclaredMethod(oracleSQLXML,GETSTRING_METHOD,new Class[]{});
              fieldValue=PrivilegedAccessHelper.invokeMethod(getStringMethod,fieldValue,new Object[]{});
            }
          }
 catch (          RuntimeException re) {
            throw re;
          }
catch (          ReflectiveOperationException|PrivilegedActionException x) {
          }
        }
 else         if (fieldValue.getClass().getName().equalsIgnoreCase(ORACLEOPAQUE_STR)) {
          try {
            Class oracleOPAQUE;
            Class xmlTypeFactoryClass;
            Constructor xmlTypeFactoryConstructor;
            Object xmlTypeFactory;
            Method getStringMethod;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
              oracleOPAQUE=AccessController.doPrivileged(new PrivilegedClassForName(ORACLEOPAQUE_STR,true,this.getClass().getClassLoader()));
              xmlTypeFactoryClass=AccessController.doPrivileged(new PrivilegedClassForName(XMLTYPEFACTORY_STR,true,this.getClass().getClassLoader()));
              xmlTypeFactoryConstructor=AccessController.doPrivileged(new PrivilegedGetConstructorFor(xmlTypeFactoryClass,new Class[0],true));
              xmlTypeFactory=AccessController.doPrivileged(new PrivilegedInvokeConstructor(xmlTypeFactoryConstructor,new Object[0]));
              getStringMethod=AccessController.doPrivileged(new PrivilegedGetDeclaredMethod(xmlTypeFactoryClass,GETSTRING_METHOD,new Class[]{oracleOPAQUE}));
              fieldValue=AccessController.doPrivileged(new PrivilegedMethodInvoker(getStringMethod,fieldValue,new Object[]{}));
            }
 else {
              oracleOPAQUE=PrivilegedAccessHelper.getClassForName(ORACLEOPAQUE_STR,false,this.getClass().getClassLoader());
              xmlTypeFactoryClass=PrivilegedAccessHelper.getClassForName(XMLTYPEFACTORY_STR,true,this.getClass().getClassLoader());
              xmlTypeFactoryConstructor=PrivilegedAccessHelper.getConstructorFor(xmlTypeFactoryClass,new Class[0],true);
              xmlTypeFactory=PrivilegedAccessHelper.invokeConstructor(xmlTypeFactoryConstructor,new Object[0]);
              getStringMethod=PrivilegedAccessHelper.getDeclaredMethod(xmlTypeFactoryClass,GETSTRING_METHOD,new Class[]{oracleOPAQUE});
              fieldValue=PrivilegedAccessHelper.invokeMethod(getStringMethod,xmlTypeFactory,new Object[]{fieldValue});
            }
          }
 catch (          RuntimeException x) {
            throw x;
          }
catch (          ReflectiveOperationException|PrivilegedActionException e) {
          }
        }
        String elementName;
        if (field.getName() == null || (elementName=sqlToXmlName(field.getName())).equals(EMPTY_STR)) {
          elementName=RESULT_STR;
        }
        Element columnElement=TEMP_DOC.createElement(elementName);
        rowElement.appendChild(columnElement);
        String fieldValueString=fieldValue.toString();
        if (result.getType().equals(BASE_64_BINARY_QNAME)) {
          fieldValueString=Helper.buildHexStringFromBytes(Base64.base64Encode((byte[])fieldValue));
          columnElement.setAttributeNS(XMLNS_URL,XSD_STR,SCHEMA_URL);
          columnElement.setAttributeNS(XMLNS_URL,XSI_STR,SCHEMA_INSTANCE_URL);
          columnElement.setAttributeNS(SCHEMA_INSTANCE_URL,XSITYPE_STR,BASE64_BINARY_STR);
        }
        columnElement.appendChild(TEMP_DOC.createTextNode(fieldValueString));
      }
    }
    simpleXMLFormatModel.simpleXML.add(rowElement);
  }
  xmlRoot.setObject(simpleXMLFormatModel);
  return xmlRoot;
}