Program: 63902
Project: 63902
Buggy source:
/** 
 * Build a Query for the given ProcedureType instance and add it to the given OR project's list of queries.
 */
@SuppressWarnings({"String_Node_Str","String_Node_Str"}) protected void buildQueryForProcedureType(ProcedureType procType,Project orProject,Project oxProject,ProcedureOperationModel opModel,boolean hasPLSQLArgs){
  StoredProcedureCall call;
  ArgumentType returnArg=procType.isFunctionType() ? ((FunctionType)procType).getReturnArgument() : null;
  boolean hasCursor=hasPLSQLCursorArg(getArgumentListForProcedureType(procType));
  hasPLSQLArgs=hasPLSQLArgs || hasCursor || opModel.isPLSQLProcedureOperation();
  if (hasPLSQLArgs) {
    if (procType.isFunctionType()) {
      org.eclipse.persistence.internal.helper.DatabaseType dType=buildDatabaseTypeFromMetadataType(returnArg,procType.getCatalogName());
      if (hasCursor) {
        call=new PLSQLStoredFunctionCall();
        ((PLSQLStoredFunctionCall)call).getArguments().remove(0);
        ((PLSQLStoredFunctionCall)call).useNamedCursorOutputAsResultSet(CURSOR_STR,dType);
      }
 else {
        Class wrapperClass=getWrapperClass(dType);
        if (wrapperClass != null) {
          ((ComplexDatabaseType)dType).setJavaType(wrapperClass);
        }
        call=new PLSQLStoredFunctionCall(dType);
        if (returnArg.getEnclosedType().isPLSQLCollectionType() && !((PLSQLCollectionType)returnArg.getEnclosedType()).isIndexed()) {
          PLSQLargument plsqlArg=((PLSQLStoredFunctionCall)call).getArguments().get(0);
          ((PLSQLCollection)plsqlArg.databaseType).setIsNestedTable(true);
        }
      }
    }
 else {
      call=new PLSQLStoredProcedureCall();
    }
  }
 else {
    if (procType.isFunctionType()) {
      String javaTypeName=returnArg.getTypeName();
      ClassDescriptor desc=oxProject.getDescriptorForAlias(getGeneratedAlias(javaTypeName));
      if (desc != null) {
        javaTypeName=desc.getJavaClassName();
      }
      if (returnArg.isComposite()) {
        DatabaseType dataType=returnArg.getEnclosedType();
        if (dataType.isVArrayType() || dataType.isObjectTableType()) {
          call=new StoredFunctionCall(Types.ARRAY,returnArg.getTypeName(),javaTypeName,buildFieldForNestedType(dataType));
        }
 else {
          call=new StoredFunctionCall(Types.STRUCT,returnArg.getTypeName(),javaTypeName);
        }
      }
 else {
        call=new StoredFunctionCall();
        if (returnArg.getEnclosedType().isBlobType()) {
          ((StoredFunctionCall)call).setResult(null,ClassConstants.BLOB);
        }
 else {
          int resultType=Util.getJDBCTypeFromTypeName(javaTypeName);
          if (resultType == Types.DATE || resultType == Types.TIME || resultType == Types.TIMESTAMP) {
            ((StoredFunctionCall)call).setResult(null,ClassConstants.TIMESTAMP);
          }
 else           if (returnArg.getEnclosedType() == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
            ((StoredFunctionCall)call).setResult(null,Types.SQLXML);
          }
 else           if (resultType == Types.OTHER || resultType == Types.CLOB) {
            ((StoredFunctionCall)call).setResult(null,ClassConstants.OBJECT);
          }
 else {
            ((StoredFunctionCall)call).setResult(null,resultType);
          }
        }
      }
    }
 else {
      call=new StoredProcedureCall();
    }
  }
  String cat=procType.getCatalogName();
  String catalogPrefix=(cat == null || cat.length() == 0) ? EMPTY_STRING : cat + DOT;
  call.setProcedureName(catalogPrefix + procType.getProcedureName());
  String returnType=opModel.getReturnType();
  boolean hasResponse=returnType != null;
  DatabaseQuery dq=null;
  if (hasCursor || (hasResponse && opModel.isCollection())) {
    dq=new DataReadQuery();
  }
 else {
    dq=new ValueReadQuery();
  }
  dq.bindAllParameters();
  dq.setName(getNameForQueryOperation(opModel,procType));
  dq.setCall(call);
  for (  ArgumentType arg : procType.getArguments()) {
    if (arg.optional()) {
      call.addOptionalArgument(arg.getArgumentName());
    }
    DatabaseType argType=arg.getEnclosedType();
    ArgumentTypeDirection direction=arg.getDirection();
    org.eclipse.persistence.internal.helper.DatabaseType databaseType=null;
    String javaTypeName=null;
    if (hasPLSQLArgs) {
      databaseType=buildDatabaseTypeFromMetadataType(argType,cat);
    }
 else {
      javaTypeName=argType.getTypeName();
      ClassDescriptor desc=oxProject.getDescriptorForAlias(getGeneratedAlias(javaTypeName));
      if (desc != null) {
        javaTypeName=desc.getJavaClassName();
      }
    }
    if (direction == IN) {
      if (hasPLSQLArgs) {
        Class wrapperClass=getWrapperClass(databaseType);
        if (wrapperClass != null) {
          ((ComplexDatabaseType)databaseType).setJavaType(wrapperClass);
        }
        ((PLSQLStoredProcedureCall)call).addNamedArgument(arg.getArgumentName(),databaseType);
        if (argType.isPLSQLCollectionType() && !((PLSQLCollectionType)argType).isIndexed()) {
          PLSQLargument plsqlArg=((PLSQLStoredProcedureCall)call).getArguments().get(((PLSQLStoredProcedureCall)call).getArguments().size() - 1);
          ((PLSQLCollection)plsqlArg.databaseType).setIsNestedTable(true);
        }
      }
 else {
        if (argType.isVArrayType()) {
          dq.addArgument(arg.getArgumentName());
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),javaTypeName);
        }
 else         if (argType.isObjectType()) {
          dq.addArgument(arg.getArgumentName());
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Types.STRUCT,argType.getTypeName(),javaTypeName);
        }
 else         if (argType.isObjectTableType()) {
          dq.addArgument(arg.getArgumentName(),java.sql.Array.class);
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),getWrapperClass(javaTypeName),buildFieldForNestedType(argType));
        }
 else {
          dq.addArgument(arg.getArgumentName());
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Util.getJDBCTypeFromTypeName(argType.getTypeName()));
        }
      }
    }
 else     if (direction == OUT) {
      if (hasPLSQLArgs) {
        if (arg.isPLSQLCursorType()) {
          ((PLSQLStoredProcedureCall)call).useNamedCursorOutputAsResultSet(arg.getArgumentName(),databaseType);
        }
 else {
          Class wrapperClass=getWrapperClass(databaseType);
          if (wrapperClass != null) {
            ((ComplexDatabaseType)databaseType).setJavaType(wrapperClass);
          }
          ((PLSQLStoredProcedureCall)call).addNamedOutputArgument(arg.getArgumentName(),databaseType);
        }
      }
 else {
        if (argType.isComposite()) {
          Class wrapperClass=getWrapperClass(javaTypeName);
          if (argType.isVArrayType() || argType.isObjectTableType()) {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),wrapperClass,buildFieldForNestedType(argType));
          }
 else {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Types.STRUCT,argType.getTypeName(),wrapperClass);
          }
        }
 else {
          if (argType == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Types.SQLXML);
          }
 else           if (argType == ScalarDatabaseTypeEnum.SYS_REFCURSOR_TYPE) {
            call.addNamedCursorOutputArgument(arg.getArgumentName());
          }
 else {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Util.getJDBCTypeFromTypeName(argType.getTypeName()));
          }
        }
      }
    }
 else {
      if (hasPLSQLArgs) {
        Class wrapperClass=getWrapperClass(databaseType);
        if (wrapperClass != null) {
          ((ComplexDatabaseType)databaseType).setJavaType(wrapperClass);
        }
        ((PLSQLStoredProcedureCall)call).addNamedInOutputArgument(arg.getArgumentName(),databaseType);
        if (argType.isPLSQLCollectionType() && !((PLSQLCollectionType)argType).isIndexed()) {
          PLSQLargument plsqlArg=((PLSQLStoredProcedureCall)call).getArguments().get(((PLSQLStoredProcedureCall)call).getArguments().size() - 1);
          ((PLSQLCollection)plsqlArg.databaseType).setIsNestedTable(true);
        }
      }
 else {
        dq.addArgument(arg.getArgumentName());
        if (argType.isComposite()) {
          Class wrapperClass=getWrapperClass(javaTypeName);
          if (argType.isVArrayType() || argType.isObjectTableType()) {
            call.addNamedInOutputArgument(arg.getArgumentName(),arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),wrapperClass,buildFieldForNestedType(argType));
          }
 else {
            call.addNamedInOutputArgument(arg.getArgumentName(),arg.getArgumentName(),arg.getArgumentName(),Types.STRUCT,argType.getTypeName());
          }
        }
 else {
          Class javaType=getClassFromJDBCType(argType.getTypeName(),dbwsBuilder.getDatabasePlatform());
          if (shouldSetJavaType(javaType.getName())) {
            call.addNamedInOutputArgument(arg.getArgumentName(),arg.getArgumentName(),arg.getArgumentName(),Util.getJDBCTypeFromTypeName(argType.getTypeName()),argType.getTypeName(),javaType);
          }
 else {
            call.addNamedInOutputArgument(arg.getArgumentName());
          }
        }
      }
    }
    if (hasPLSQLArgs && (direction == IN || direction == INOUT)) {
      ClassDescriptor xdesc=null;
      if (hasResponse) {
        int idx=returnType.indexOf(COLON);
        if (idx == -1) {
          idx=returnType.indexOf(CLOSE_PAREN);
        }
        if (idx > 0) {
          String typ=returnType.substring(idx + 1);
          for (          XMLDescriptor xd : (List<XMLDescriptor>)(List)oxProject.getOrderedDescriptors()) {
            if (xd.getSchemaReference() != null) {
              String context=xd.getSchemaReference().getSchemaContext();
              if (context.substring(1).equals(typ)) {
                xdesc=xd;
                break;
              }
            }
          }
        }
      }
      if (xdesc != null) {
        dq.addArgumentByTypeName(arg.getArgumentName(),xdesc.getJavaClassName());
      }
 else {
        if (databaseType instanceof PLSQLCollection || databaseType instanceof VArrayType) {
          dq.addArgument(arg.getArgumentName(),Array.class);
        }
 else         if (databaseType instanceof PLSQLrecord || databaseType instanceof OracleObjectType) {
          dq.addArgument(arg.getArgumentName(),Struct.class);
        }
 else {
          dq.addArgument(arg.getArgumentName(),JDBCTypes.getClassForCode(databaseType.getConversionCode()));
        }
      }
    }
  }
  orProject.getQueries().add(dq);
}

Fixed version (ground truth):
/** 
 * Build a Query for the given ProcedureType instance and add it to the given OR project's list of queries.
 */
@SuppressWarnings({"String_Node_Str","String_Node_Str"}) protected void buildQueryForProcedureType(ProcedureType procType,Project orProject,Project oxProject,ProcedureOperationModel opModel,boolean hasPLSQLArgs){
  StoredProcedureCall call;
  ArgumentType returnArg=procType.isFunctionType() ? ((FunctionType)procType).getReturnArgument() : null;
  boolean hasCursor=hasPLSQLCursorArg(getArgumentListForProcedureType(procType));
  hasPLSQLArgs=hasPLSQLArgs || hasCursor || opModel.isPLSQLProcedureOperation();
  if (hasPLSQLArgs) {
    if (procType.isFunctionType()) {
      org.eclipse.persistence.internal.helper.DatabaseType dType=buildDatabaseTypeFromMetadataType(returnArg,procType.getCatalogName());
      if (hasCursor) {
        call=new PLSQLStoredFunctionCall();
        ((PLSQLStoredFunctionCall)call).getArguments().remove(0);
        ((PLSQLStoredFunctionCall)call).useNamedCursorOutputAsResultSet(CURSOR_STR,dType);
      }
 else {
        Class wrapperClass=getWrapperClass(dType);
        if (wrapperClass != null) {
          ((ComplexDatabaseType)dType).setJavaType(wrapperClass);
        }
        call=new PLSQLStoredFunctionCall(dType);
        if (returnArg.getEnclosedType().isPLSQLCollectionType() && !((PLSQLCollectionType)returnArg.getEnclosedType()).isIndexed()) {
          PLSQLargument plsqlArg=((PLSQLStoredFunctionCall)call).getArguments().get(0);
          ((PLSQLCollection)plsqlArg.databaseType).setIsNestedTable(true);
        }
      }
    }
 else {
      call=new PLSQLStoredProcedureCall();
    }
  }
 else {
    if (procType.isFunctionType()) {
      String javaTypeName=returnArg.getTypeName();
      ClassDescriptor desc=oxProject.getDescriptorForAlias(getGeneratedAlias(javaTypeName));
      if (desc != null) {
        javaTypeName=desc.getJavaClassName();
      }
      if (returnArg.isComposite()) {
        DatabaseType dataType=returnArg.getEnclosedType();
        if (dataType.isVArrayType() || dataType.isObjectTableType()) {
          call=new StoredFunctionCall(Types.ARRAY,returnArg.getTypeName(),javaTypeName,buildFieldForNestedType(dataType));
        }
 else {
          call=new StoredFunctionCall(Types.STRUCT,returnArg.getTypeName(),javaTypeName);
        }
      }
 else {
        call=new StoredFunctionCall();
        if (returnArg.getEnclosedType().isBlobType()) {
          ((StoredFunctionCall)call).setResult(null,ClassConstants.BLOB);
        }
 else {
          int resultType=Util.getJDBCTypeFromTypeName(javaTypeName);
          if (resultType == Types.DATE || resultType == Types.TIME || resultType == Types.TIMESTAMP) {
            ((StoredFunctionCall)call).setResult(null,ClassConstants.TIMESTAMP);
          }
 else           if (returnArg.getEnclosedType() == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
            ((StoredFunctionCall)call).setResult(getJDBCTypeForTypeName(XMLTYPE_STR),XMLTYPE_STR,ClassConstants.OBJECT);
          }
 else           if (resultType == Types.OTHER || resultType == Types.CLOB) {
            ((StoredFunctionCall)call).setResult(null,ClassConstants.OBJECT);
          }
 else {
            ((StoredFunctionCall)call).setResult(null,resultType);
          }
        }
      }
    }
 else {
      call=new StoredProcedureCall();
    }
  }
  String cat=procType.getCatalogName();
  String catalogPrefix=(cat == null || cat.length() == 0) ? EMPTY_STRING : cat + DOT;
  call.setProcedureName(catalogPrefix + procType.getProcedureName());
  String returnType=opModel.getReturnType();
  boolean hasResponse=returnType != null;
  DatabaseQuery dq=null;
  if (hasCursor || (hasResponse && opModel.isCollection())) {
    dq=new DataReadQuery();
  }
 else {
    dq=new ValueReadQuery();
  }
  dq.bindAllParameters();
  dq.setName(getNameForQueryOperation(opModel,procType));
  dq.setCall(call);
  for (  ArgumentType arg : procType.getArguments()) {
    if (arg.optional()) {
      call.addOptionalArgument(arg.getArgumentName());
    }
    DatabaseType argType=arg.getEnclosedType();
    ArgumentTypeDirection direction=arg.getDirection();
    org.eclipse.persistence.internal.helper.DatabaseType databaseType=null;
    String javaTypeName=null;
    if (hasPLSQLArgs) {
      databaseType=buildDatabaseTypeFromMetadataType(argType,cat);
    }
 else {
      javaTypeName=argType.getTypeName();
      ClassDescriptor desc=oxProject.getDescriptorForAlias(getGeneratedAlias(javaTypeName));
      if (desc != null) {
        javaTypeName=desc.getJavaClassName();
      }
    }
    if (direction == IN) {
      if (hasPLSQLArgs) {
        Class wrapperClass=getWrapperClass(databaseType);
        if (wrapperClass != null) {
          ((ComplexDatabaseType)databaseType).setJavaType(wrapperClass);
        }
        ((PLSQLStoredProcedureCall)call).addNamedArgument(arg.getArgumentName(),databaseType);
        if (argType.isPLSQLCollectionType() && !((PLSQLCollectionType)argType).isIndexed()) {
          PLSQLargument plsqlArg=((PLSQLStoredProcedureCall)call).getArguments().get(((PLSQLStoredProcedureCall)call).getArguments().size() - 1);
          ((PLSQLCollection)plsqlArg.databaseType).setIsNestedTable(true);
        }
      }
 else {
        if (argType.isVArrayType()) {
          dq.addArgument(arg.getArgumentName());
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),javaTypeName);
        }
 else         if (argType.isObjectType()) {
          dq.addArgument(arg.getArgumentName());
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Types.STRUCT,argType.getTypeName(),javaTypeName);
        }
 else         if (argType.isObjectTableType()) {
          dq.addArgument(arg.getArgumentName(),java.sql.Array.class);
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),getWrapperClass(javaTypeName),buildFieldForNestedType(argType));
        }
 else {
          dq.addArgument(arg.getArgumentName());
          call.addNamedArgument(arg.getArgumentName(),arg.getArgumentName(),Util.getJDBCTypeFromTypeName(argType.getTypeName()));
        }
      }
    }
 else     if (direction == OUT) {
      if (hasPLSQLArgs) {
        if (arg.isPLSQLCursorType()) {
          ((PLSQLStoredProcedureCall)call).useNamedCursorOutputAsResultSet(arg.getArgumentName(),databaseType);
        }
 else {
          Class wrapperClass=getWrapperClass(databaseType);
          if (wrapperClass != null) {
            ((ComplexDatabaseType)databaseType).setJavaType(wrapperClass);
          }
          ((PLSQLStoredProcedureCall)call).addNamedOutputArgument(arg.getArgumentName(),databaseType);
        }
      }
 else {
        if (argType.isComposite()) {
          Class wrapperClass=getWrapperClass(javaTypeName);
          if (argType.isVArrayType() || argType.isObjectTableType()) {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),wrapperClass,buildFieldForNestedType(argType));
          }
 else {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Types.STRUCT,argType.getTypeName(),wrapperClass);
          }
        }
 else {
          if (argType == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),getJDBCTypeForTypeName(XMLTYPE_STR),XMLTYPE_STR);
          }
 else           if (argType == ScalarDatabaseTypeEnum.SYS_REFCURSOR_TYPE) {
            call.addNamedCursorOutputArgument(arg.getArgumentName());
          }
 else {
            call.addNamedOutputArgument(arg.getArgumentName(),arg.getArgumentName(),Util.getJDBCTypeFromTypeName(argType.getTypeName()));
          }
        }
      }
    }
 else {
      if (hasPLSQLArgs) {
        Class wrapperClass=getWrapperClass(databaseType);
        if (wrapperClass != null) {
          ((ComplexDatabaseType)databaseType).setJavaType(wrapperClass);
        }
        ((PLSQLStoredProcedureCall)call).addNamedInOutputArgument(arg.getArgumentName(),databaseType);
        if (argType.isPLSQLCollectionType() && !((PLSQLCollectionType)argType).isIndexed()) {
          PLSQLargument plsqlArg=((PLSQLStoredProcedureCall)call).getArguments().get(((PLSQLStoredProcedureCall)call).getArguments().size() - 1);
          ((PLSQLCollection)plsqlArg.databaseType).setIsNestedTable(true);
        }
      }
 else {
        dq.addArgument(arg.getArgumentName());
        if (argType.isComposite()) {
          Class wrapperClass=getWrapperClass(javaTypeName);
          if (argType.isVArrayType() || argType.isObjectTableType()) {
            call.addNamedInOutputArgument(arg.getArgumentName(),arg.getArgumentName(),arg.getArgumentName(),Types.ARRAY,argType.getTypeName(),wrapperClass,buildFieldForNestedType(argType));
          }
 else {
            call.addNamedInOutputArgument(arg.getArgumentName(),arg.getArgumentName(),arg.getArgumentName(),Types.STRUCT,argType.getTypeName());
          }
        }
 else {
          Class javaType=getClassFromJDBCType(argType.getTypeName(),dbwsBuilder.getDatabasePlatform());
          if (shouldSetJavaType(javaType.getName())) {
            call.addNamedInOutputArgument(arg.getArgumentName(),arg.getArgumentName(),arg.getArgumentName(),Util.getJDBCTypeFromTypeName(argType.getTypeName()),argType.getTypeName(),javaType);
          }
 else {
            call.addNamedInOutputArgument(arg.getArgumentName());
          }
        }
      }
    }
    if (hasPLSQLArgs && (direction == IN || direction == INOUT)) {
      ClassDescriptor xdesc=null;
      if (hasResponse) {
        int idx=returnType.indexOf(COLON);
        if (idx == -1) {
          idx=returnType.indexOf(CLOSE_PAREN);
        }
        if (idx > 0) {
          String typ=returnType.substring(idx + 1);
          for (          XMLDescriptor xd : (List<XMLDescriptor>)(List)oxProject.getOrderedDescriptors()) {
            if (xd.getSchemaReference() != null) {
              String context=xd.getSchemaReference().getSchemaContext();
              if (context.substring(1).equals(typ)) {
                xdesc=xd;
                break;
              }
            }
          }
        }
      }
      if (xdesc != null) {
        dq.addArgumentByTypeName(arg.getArgumentName(),xdesc.getJavaClassName());
      }
 else {
        if (databaseType instanceof PLSQLCollection || databaseType instanceof VArrayType) {
          dq.addArgument(arg.getArgumentName(),Array.class);
        }
 else         if (databaseType instanceof PLSQLrecord || databaseType instanceof OracleObjectType) {
          dq.addArgument(arg.getArgumentName(),Struct.class);
        }
 else {
          dq.addArgument(arg.getArgumentName(),JDBCTypes.getClassForCode(databaseType.getConversionCode()));
        }
      }
    }
  }
  orProject.getQueries().add(dq);
}