Program: 80022
Project: 80022
Buggy source:
/** 
 * Resolve a routine. Obtain a list of routines from the data dictionary of the correct type (functions or procedures) and name. Pick the best routine from the list. Currently only a single routine with a given type and name is allowed, thus if changes are made to support overloaded routines, careful code inspection and testing will be required.
 * @param fromList
 * @param subqueryList
 * @param aggregateVector
 * @param sd
 * @throws StandardException
 */
private void resolveRoutine(FromList fromList,SubqueryList subqueryList,Vector aggregateVector,SchemaDescriptor sd) throws StandardException {
  if (sd.getUUID() != null) {
    java.util.List list=getDataDictionary().getRoutineList(sd.getUUID().toString(),methodName,forCallStatement ? AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR);
    for (int i=list.size() - 1; i >= 0; i--) {
      AliasDescriptor proc=(AliasDescriptor)list.get(i);
      RoutineAliasInfo routineInfo=(RoutineAliasInfo)proc.getAliasInfo();
      int parameterCount=routineInfo.getParameterCount();
      boolean hasVarargs=routineInfo.hasVarargs();
      if (hasVarargs) {
        if (methodParms.length < (parameterCount - 1)) {
          continue;
        }
      }
 else       if (parameterCount != methodParms.length) {
        continue;
      }
      TypeDescriptor[] parameterTypes=routineInfo.getParameterTypes();
      int sigParameterCount=parameterCount;
      if (routineInfo.getMaxDynamicResultSets() > 0) {
        sigParameterCount++;
      }
      signature=new JSQLType[sigParameterCount];
      for (int p=0; p < parameterCount; p++) {
        TypeDescriptor td=parameterTypes[p];
        TypeId typeId=TypeId.getTypeId(td);
        TypeId parameterTypeId=typeId;
        int parameterMode=routineInfo.getParameterModes()[p];
        if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {
          String arrayType;
switch (typeId.getJDBCTypeId()) {
case java.sql.Types.BOOLEAN:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
case java.sql.Types.BIGINT:
case java.sql.Types.REAL:
case java.sql.Types.DOUBLE:
            arrayType=getTypeCompiler(typeId).getCorrespondingPrimitiveTypeName().concat("String_Node_Str");
          break;
default :
        arrayType=typeId.getCorrespondingJavaTypeName().concat("String_Node_Str");
      break;
  }
  typeId=TypeId.getUserDefinedTypeId(arrayType);
}
DataTypeDescriptor methoddtd=new DataTypeDescriptor(typeId,td.getPrecision(),td.getScale(),td.isNullable(),td.getMaximumWidth());
signature[p]=new JSQLType(methoddtd);
DataTypeDescriptor paramdtd=new DataTypeDescriptor(parameterTypeId,td.getPrecision(),td.getScale(),td.isNullable(),td.getMaximumWidth());
if (hasVarargs && (p == parameterCount - 1)) {
  for (int idx=p; idx < methodParms.length; idx++) {
    coerceMethodParameter(fromList,subqueryList,aggregateVector,parameterCount,paramdtd,parameterTypeId,parameterMode,idx);
  }
}
 else {
  coerceMethodParameter(fromList,subqueryList,aggregateVector,parameterCount,paramdtd,parameterTypeId,parameterMode,p);
}
}
if (sigParameterCount != parameterCount) {
DataTypeDescriptor dtd=new DataTypeDescriptor(TypeId.getUserDefinedTypeId("String_Node_Str"),0,0,false,-1);
signature[parameterCount]=new JSQLType(dtd);
}
this.routineInfo=routineInfo;
ad=proc;
if (sd.isSystemSchema() && (routineInfo.getReturnType() == null) && routineInfo.getSQLAllowed() != RoutineAliasInfo.NO_SQL) {
isSystemCode=true;
}
routineDefiner=sd.getAuthorizationId();
break;
}
}
if ((ad == null) && (methodParms.length == 1)) {
ad=AggregateNode.resolveAggregate(getDataDictionary(),sd,methodName);
}
}

Fixed version (ground truth):
/** 
 * Resolve a routine. Obtain a list of routines from the data dictionary of the correct type (functions or procedures) and name. Pick the best routine from the list. Currently only a single routine with a given type and name is allowed, thus if changes are made to support overloaded routines, careful code inspection and testing will be required.
 * @param fromList
 * @param subqueryList
 * @param aggregateVector
 * @param sd
 * @throws StandardException
 */
private void resolveRoutine(FromList fromList,SubqueryList subqueryList,Vector aggregateVector,SchemaDescriptor sd) throws StandardException {
  if (sd.getUUID() != null) {
    java.util.List list=getDataDictionary().getRoutineList(sd.getUUID().toString(),methodName,forCallStatement ? AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR);
    for (int i=list.size() - 1; i >= 0; i--) {
      AliasDescriptor proc=(AliasDescriptor)list.get(i);
      RoutineAliasInfo routineInfo=(RoutineAliasInfo)proc.getAliasInfo();
      int parameterCount=routineInfo.getParameterCount();
      boolean hasVarargs=routineInfo.hasVarargs();
      if (hasVarargs) {
        if (methodParms.length < (parameterCount - 1)) {
          continue;
        }
      }
 else       if (parameterCount != methodParms.length) {
        continue;
      }
      TypeDescriptor[] parameterTypes=routineInfo.getParameterTypes();
      int sigParameterCount=parameterCount;
      if (routineInfo.getMaxDynamicResultSets() > 0) {
        sigParameterCount++;
      }
      signature=new JSQLType[sigParameterCount];
      for (int p=0; p < parameterCount; p++) {
        TypeDescriptor td=parameterTypes[p];
        TypeId typeId=TypeId.getTypeId(td);
        TypeId parameterTypeId=typeId;
        int parameterMode=routineInfo.getParameterModes()[getRoutineArgIdx(routineInfo,p)];
        if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {
          String arrayType;
switch (typeId.getJDBCTypeId()) {
case java.sql.Types.BOOLEAN:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
case java.sql.Types.BIGINT:
case java.sql.Types.REAL:
case java.sql.Types.DOUBLE:
            arrayType=getTypeCompiler(typeId).getCorrespondingPrimitiveTypeName().concat("String_Node_Str");
          break;
default :
        arrayType=typeId.getCorrespondingJavaTypeName().concat("String_Node_Str");
      break;
  }
  typeId=TypeId.getUserDefinedTypeId(arrayType);
}
DataTypeDescriptor methoddtd=new DataTypeDescriptor(typeId,td.getPrecision(),td.getScale(),td.isNullable(),td.getMaximumWidth());
signature[p]=new JSQLType(methoddtd);
DataTypeDescriptor paramdtd=new DataTypeDescriptor(parameterTypeId,td.getPrecision(),td.getScale(),td.isNullable(),td.getMaximumWidth());
if (hasVarargs && (p == parameterCount - 1)) {
  for (int idx=p; idx < methodParms.length; idx++) {
    coerceMethodParameter(fromList,subqueryList,aggregateVector,methodParms.length,paramdtd,parameterTypeId,parameterMode,idx);
  }
}
 else {
  coerceMethodParameter(fromList,subqueryList,aggregateVector,methodParms.length,paramdtd,parameterTypeId,parameterMode,p);
}
}
if (sigParameterCount != parameterCount) {
DataTypeDescriptor dtd=new DataTypeDescriptor(TypeId.getUserDefinedTypeId("String_Node_Str"),0,0,false,-1);
signature[parameterCount]=new JSQLType(dtd);
}
this.routineInfo=routineInfo;
ad=proc;
if (sd.isSystemSchema() && (routineInfo.getReturnType() == null) && routineInfo.getSQLAllowed() != RoutineAliasInfo.NO_SQL) {
isSystemCode=true;
}
routineDefiner=sd.getAuthorizationId();
break;
}
}
if ((ad == null) && (methodParms.length == 1)) {
ad=AggregateNode.resolveAggregate(getDataDictionary(),sd,methodName);
}
}