Program: 64990
Project: 64990
Buggy source:
/** 
 * Execute <tt>SELECT</tt> operation on the database
 * @param xrService parent <code>XRService</code> that owns this <code>Operation</code>
 * @param invocation contains runtime argument values to be bound to the list of{@link Parameter}'s.
 * @return  result - the result of the underlying <tt>SELECT</tt> operation onthe database, or <code>null</code>.
 * @see  {@link Operation}
 */
@Override public Object invoke(XRServiceAdapter xrService,Invocation invocation){
  DatabaseQuery query=queryHandler.getDatabaseQuery();
  List queryArguments=query.getArguments();
  int queryArgumentsSize=queryArguments.size();
  Vector executeArguments=new NonSynchronizedVector();
  for (int i=0; i < queryArgumentsSize; i++) {
    String argName=(String)queryArguments.get(i);
    executeArguments.add(invocation.getParameter(argName));
  }
  Object value=xrService.getORSession().getActiveSession().executeQuery(query,executeArguments);
  if (value != null) {
    if (isSimpleXMLFormat()) {
      value=createSimpleXMLFormat(xrService,value);
    }
 else {
      QName resultType=getResultType();
      if (resultType != null) {
        if (isAttachment() || (!isCollection() && resultType.equals(BASE_64_BINARY_QNAME))) {
          String mimeType=DEFAULT_ATTACHMENT_MIMETYPE;
          if (isAttachment() && result.getAttachment().getMimeType() != null) {
            mimeType=result.getAttachment().getMimeType();
          }
          return AttachmentHelper.buildAttachmentHandler((byte[])value,mimeType);
        }
        if (resultType.getNamespaceURI().equals(W3C_XML_SCHEMA_NS_URI)) {
          ValueObject vo=new ValueObject();
          vo.value=value;
          value=vo;
        }
 else {
          Object targetObject=value;
          if (xrService.descriptorsByQName.containsKey(resultType)) {
            XMLDescriptor xdesc=xrService.descriptorsByQName.get(resultType);
            ClassDescriptor desc=xrService.getORSession().getDescriptorForAlias(xdesc.getAlias());
            if (desc.isAggregateDescriptor() && !desc.isObjectRelationalDataTypeDescriptor()) {
              if (isCollection()) {
                XRDynamicEntity_CollectionWrapper xrCollWrapper=new XRDynamicEntity_CollectionWrapper();
                Vector<AbstractRecord> results=(Vector<AbstractRecord>)value;
                for (int i=0, len=results.size(); i < len; i++) {
                  Object o=desc.getObjectBuilder().buildNewInstance();
                  populateTargetObjectFromRecord(desc.getMappings(),results.get(i),o,(AbstractSession)xrService.getORSession());
                  xrCollWrapper.add(o);
                }
                targetObject=xrCollWrapper;
              }
 else {
                targetObject=desc.getObjectBuilder().buildNewInstance();
                populateTargetObjectFromRecord(desc.getMappings(),(AbstractRecord)((Vector)value).get(0),targetObject,(AbstractSession)xrService.getORSession());
              }
            }
          }
          value=targetObject;
        }
      }
    }
  }
  return value;
}

Fixed version (ground truth):
/** 
 * Execute <tt>SELECT</tt> operation on the database
 * @param xrService parent <code>XRService</code> that owns this <code>Operation</code>
 * @param invocation contains runtime argument values to be bound to the list of{@link Parameter}'s.
 * @return  result - the result of the underlying <tt>SELECT</tt> operation onthe database, or <code>null</code>.
 * @see  {@link Operation}
 */
@Override public Object invoke(XRServiceAdapter xrService,Invocation invocation){
  DatabaseQuery query=queryHandler.getDatabaseQuery();
  List queryArguments=query.getArguments();
  int queryArgumentsSize=queryArguments.size();
  Vector executeArguments=new NonSynchronizedVector();
  for (int i=0; i < queryArgumentsSize; i++) {
    String argName=(String)queryArguments.get(i);
    executeArguments.add(invocation.getParameter(argName));
  }
  Object value=xrService.getORSession().getActiveSession().executeQuery(query,executeArguments);
  if (value != null) {
    if (isSimpleXMLFormat()) {
      value=createSimpleXMLFormat(xrService,value);
    }
 else {
      QName resultType=getResultType();
      if (resultType != null) {
        if (isAttachment() || (!isCollection() && resultType.equals(BASE_64_BINARY_QNAME))) {
          String mimeType=DEFAULT_ATTACHMENT_MIMETYPE;
          if (isAttachment() && result.getAttachment().getMimeType() != null) {
            mimeType=result.getAttachment().getMimeType();
          }
          if (value instanceof Blob) {
            value=((XMLConversionManager)xrService.getOXSession().getDatasourcePlatform().getConversionManager()).convertObject((Blob)value,ClassConstants.APBYTE);
          }
          return AttachmentHelper.buildAttachmentHandler((byte[])value,mimeType);
        }
        if (resultType.getNamespaceURI().equals(W3C_XML_SCHEMA_NS_URI)) {
          ValueObject vo=new ValueObject();
          vo.value=value;
          value=vo;
        }
 else {
          Object targetObject=value;
          if (xrService.descriptorsByQName.containsKey(resultType)) {
            XMLDescriptor xdesc=xrService.descriptorsByQName.get(resultType);
            ClassDescriptor desc=xrService.getORSession().getDescriptorForAlias(xdesc.getAlias());
            if (desc.isAggregateDescriptor() && !desc.isObjectRelationalDataTypeDescriptor()) {
              if (isCollection()) {
                XRDynamicEntity_CollectionWrapper xrCollWrapper=new XRDynamicEntity_CollectionWrapper();
                Vector<AbstractRecord> results=(Vector<AbstractRecord>)value;
                for (int i=0, len=results.size(); i < len; i++) {
                  Object o=desc.getObjectBuilder().buildNewInstance();
                  populateTargetObjectFromRecord(desc.getMappings(),results.get(i),o,(AbstractSession)xrService.getORSession());
                  xrCollWrapper.add(o);
                }
                targetObject=xrCollWrapper;
              }
 else {
                targetObject=desc.getObjectBuilder().buildNewInstance();
                populateTargetObjectFromRecord(desc.getMappings(),(AbstractRecord)((Vector)value).get(0),targetObject,(AbstractSession)xrService.getORSession());
              }
            }
          }
          value=targetObject;
        }
      }
    }
  }
  return value;
}