Program: 80023
Project: 80023
Buggy source:
/** 
 * Do code generation for this method call
 * @param acb	The ExpressionClassBuilder for the class we're generating
 * @param mb	The method the expression will go into
 * @exception StandardException		Thrown on error
 */
public void generateExpression(ExpressionClassBuilder acb,MethodBuilder mb) throws StandardException {
  if (routineInfo != null) {
    if (!routineInfo.calledOnNullInput() && routineInfo.getParameterCount() != 0)     returnsNullOnNullState=acb.newFieldDeclaration(Modifier.PRIVATE,"String_Node_Str");
  }
  if (returnsNullOnNullState != null) {
    mb.push(false);
    mb.setField(returnsNullOnNullState);
    mb.pushThis();
  }
  int nargs=generateParameters(acb,mb);
  LocalField functionEntrySQLAllowed=null;
  if (routineInfo != null) {
    short sqlAllowed=routineInfo.getSQLAllowed();
    if (sqlAllowed != RoutineAliasInfo.NO_SQL) {
      int sqlOperation;
      if (sqlAllowed == RoutineAliasInfo.READS_SQL_DATA)       sqlOperation=Authorizer.SQL_SELECT_OP;
 else       if (sqlAllowed == RoutineAliasInfo.MODIFIES_SQL_DATA)       sqlOperation=Authorizer.SQL_WRITE_OP;
 else       sqlOperation=Authorizer.SQL_ARBITARY_OP;
      generateAuthorizeCheck((ActivationClassBuilder)acb,mb,sqlOperation);
    }
    int statmentContextReferences=isSystemCode ? 2 : 1;
    boolean isFunction=routineInfo.getReturnType() != null;
    if (isFunction)     statmentContextReferences++;
    if (statmentContextReferences != 0) {
      acb.pushThisAsActivation(mb);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.LanguageConnectionContext,0);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
      for (int scc=1; scc < statmentContextReferences; scc++)       mb.dup();
    }
    if (isSystemCode) {
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
    }
    if (sqlAllowed != RoutineAliasInfo.NO_SQL) {
      generateSetupNestedSessionContext((ActivationClassBuilder)acb,mb,routineInfo.hasDefinersRights(),routineDefiner);
    }
    if (isFunction) {
      functionEntrySQLAllowed=acb.newFieldDeclaration(Modifier.PRIVATE,"String_Node_Str");
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
      mb.setField(functionEntrySQLAllowed);
    }
    mb.push(sqlAllowed);
    mb.push(false);
    mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",2);
  }
  if (routineInfo != null && !hasVarargs()) {
    int compiledResultSets=methodParameterTypes.length - methodParms.length;
    if (compiledResultSets != 0) {
      int maxDynamicResults=routineInfo.getMaxDynamicResultSets();
      if (maxDynamicResults > 0) {
        MethodBuilder gdr=acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC,"String_Node_Str","String_Node_Str");
        gdr.push(maxDynamicResults);
        gdr.methodReturn();
        gdr.complete();
      }
      MethodBuilder gdr=acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC,"String_Node_Str","String_Node_Str");
      MethodBuilder cons=acb.getConstructor();
{
        LocalField procedureResultSetsHolder=acb.newFieldDeclaration(Modifier.PRIVATE,"String_Node_Str");
        gdr.getField(procedureResultSetsHolder);
        cons.pushNewArray("String_Node_Str",compiledResultSets);
        cons.setField(procedureResultSetsHolder);
        for (int i=0; i < compiledResultSets; i++) {
          mb.pushNewArray("String_Node_Str",1);
          mb.dup();
          mb.getField(procedureResultSetsHolder);
          mb.swap();
          mb.setArrayElement(i);
        }
      }
      gdr.methodReturn();
      gdr.complete();
      nargs+=compiledResultSets;
    }
  }
  String javaReturnType=getJavaTypeName();
  MethodBuilder mbnc=null;
  MethodBuilder mbcm=mb;
  if (returnsNullOnNullState != null) {
    mbnc=acb.newGeneratedFun(javaReturnType,Modifier.PRIVATE,methodParameterTypes);
    Class[] throwsSet=((java.lang.reflect.Method)method).getExceptionTypes();
    for (int te=0; te < throwsSet.length; te++) {
      mbnc.addThrownException(throwsSet[te].getName());
    }
    mbnc.getField(returnsNullOnNullState);
    mbnc.conditionalIf();
    mbnc.pushNull(javaReturnType);
    mbnc.startElseCode();
    if (!actualMethodReturnType.equals(javaReturnType))     mbnc.pushNewStart(javaReturnType);
    for (int pa=0; pa < nargs; pa++) {
      mbnc.getParameter(pa);
    }
    mbcm=mbnc;
  }
  mbcm.callMethod(VMOpcode.INVOKESTATIC,method.getDeclaringClass().getName(),methodName,actualMethodReturnType,nargs);
  if (returnsNullOnNullState != null) {
    if (!actualMethodReturnType.equals(javaReturnType)) {
      if (actualMethodReturnType.equals("String_Node_Str") && javaReturnType.equals("String_Node_Str"))       mbnc.upCast("String_Node_Str");
      mbnc.pushNewComplete(1);
    }
    mbnc.completeConditional();
    mbnc.methodReturn();
    mbnc.complete();
    mb.callMethod(VMOpcode.INVOKEVIRTUAL,acb.getClassBuilder().getFullName(),mbnc.getName(),javaReturnType,nargs);
    mbnc=null;
  }
  if (routineInfo != null) {
    if (functionEntrySQLAllowed != null) {
      acb.pushThisAsActivation(mb);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.LanguageConnectionContext,0);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
      mb.getField(functionEntrySQLAllowed);
      mb.push(true);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",2);
    }
    if (outParamArrays != null) {
      MethodBuilder constructor=acb.getConstructor();
      acb.pushThisAsActivation(constructor);
      constructor.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.ParameterValueSet,0);
      acb.pushThisAsActivation(mb);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.ParameterValueSet,0);
      int[] parameterModes=routineInfo.getParameterModes();
      for (int i=0; i < outParamArrays.length; i++) {
        int parameterMode=parameterModes[i];
        if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {
          ValueNode sqlParamNode=((SQLToJavaValueNode)methodParms[i]).getSQLValueNode();
          int applicationParameterNumber=applicationParameterNumbers[i];
          constructor.dup();
          constructor.push(applicationParameterNumber);
          constructor.push(parameterMode);
          constructor.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",2);
          LocalField lf=outParamArrays[i];
          mb.dup();
          mb.push(applicationParameterNumber);
          mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.DataValueDescriptor,1);
          DataTypeDescriptor paramdtd=sqlParamNode.getTypeServices();
          boolean isNumericType=paramdtd.getTypeId().isNumericTypeId();
          boolean isAnsiUDT=paramdtd.getTypeId().getBaseTypeId().isAnsiUDT();
          boolean isPrimitive=((java.lang.reflect.Method)method).getParameterTypes()[i].getComponentType().isPrimitive();
          if (isNumericType) {
            if (!isPrimitive)             mb.cast(ClassName.NumberDataValue);
          }
 else           if (paramdtd.getTypeId().isBooleanTypeId()) {
            if (!isPrimitive)             mb.cast(ClassName.BooleanDataValue);
          }
          if (paramdtd.getTypeId().variableLength()) {
            mb.dup();
          }
          mb.getField(lf);
          mb.getArrayElement(0);
          if (isNumericType && !isPrimitive) {
            mb.upCast("String_Node_Str");
          }
          if (isAnsiUDT) {
            mb.upCast("String_Node_Str");
          }
          mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",1);
          if (paramdtd.getTypeId().variableLength()) {
            mb.push(isNumericType ? paramdtd.getPrecision() : paramdtd.getMaximumWidth());
            mb.push(paramdtd.getScale());
            mb.push(isNumericType);
            mb.callMethod(VMOpcode.INVOKEINTERFACE,ClassName.VariableSizeDataValue,"String_Node_Str","String_Node_Str",3);
          }
        }
      }
      constructor.endStatement();
      mb.endStatement();
    }
  }
}

Fixed version (ground truth):
/** 
 * Do code generation for this method call
 * @param acb	The ExpressionClassBuilder for the class we're generating
 * @param mb	The method the expression will go into
 * @exception StandardException		Thrown on error
 */
public void generateExpression(ExpressionClassBuilder acb,MethodBuilder mb) throws StandardException {
  if (routineInfo != null) {
    if (!routineInfo.calledOnNullInput() && routineInfo.getParameterCount() != 0)     returnsNullOnNullState=acb.newFieldDeclaration(Modifier.PRIVATE,"String_Node_Str");
  }
  if (returnsNullOnNullState != null) {
    mb.push(false);
    mb.setField(returnsNullOnNullState);
    mb.pushThis();
  }
  int nargs=generateParameters(acb,mb);
  LocalField functionEntrySQLAllowed=null;
  if (routineInfo != null) {
    short sqlAllowed=routineInfo.getSQLAllowed();
    if (sqlAllowed != RoutineAliasInfo.NO_SQL) {
      int sqlOperation;
      if (sqlAllowed == RoutineAliasInfo.READS_SQL_DATA)       sqlOperation=Authorizer.SQL_SELECT_OP;
 else       if (sqlAllowed == RoutineAliasInfo.MODIFIES_SQL_DATA)       sqlOperation=Authorizer.SQL_WRITE_OP;
 else       sqlOperation=Authorizer.SQL_ARBITARY_OP;
      generateAuthorizeCheck((ActivationClassBuilder)acb,mb,sqlOperation);
    }
    int statmentContextReferences=isSystemCode ? 2 : 1;
    boolean isFunction=routineInfo.getReturnType() != null;
    if (isFunction)     statmentContextReferences++;
    if (statmentContextReferences != 0) {
      acb.pushThisAsActivation(mb);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.LanguageConnectionContext,0);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
      for (int scc=1; scc < statmentContextReferences; scc++)       mb.dup();
    }
    if (isSystemCode) {
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
    }
    if (sqlAllowed != RoutineAliasInfo.NO_SQL) {
      generateSetupNestedSessionContext((ActivationClassBuilder)acb,mb,routineInfo.hasDefinersRights(),routineDefiner);
    }
    if (isFunction) {
      functionEntrySQLAllowed=acb.newFieldDeclaration(Modifier.PRIVATE,"String_Node_Str");
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
      mb.setField(functionEntrySQLAllowed);
    }
    mb.push(sqlAllowed);
    mb.push(false);
    mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",2);
  }
  if (routineInfo != null && !hasVarargs()) {
    int compiledResultSets=methodParameterTypes.length - methodParms.length;
    if (compiledResultSets != 0) {
      int maxDynamicResults=routineInfo.getMaxDynamicResultSets();
      if (maxDynamicResults > 0) {
        MethodBuilder gdr=acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC,"String_Node_Str","String_Node_Str");
        gdr.push(maxDynamicResults);
        gdr.methodReturn();
        gdr.complete();
      }
      MethodBuilder gdr=acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC,"String_Node_Str","String_Node_Str");
      MethodBuilder cons=acb.getConstructor();
{
        LocalField procedureResultSetsHolder=acb.newFieldDeclaration(Modifier.PRIVATE,"String_Node_Str");
        gdr.getField(procedureResultSetsHolder);
        cons.pushNewArray("String_Node_Str",compiledResultSets);
        cons.setField(procedureResultSetsHolder);
        for (int i=0; i < compiledResultSets; i++) {
          mb.pushNewArray("String_Node_Str",1);
          mb.dup();
          mb.getField(procedureResultSetsHolder);
          mb.swap();
          mb.setArrayElement(i);
        }
      }
      gdr.methodReturn();
      gdr.complete();
      nargs+=compiledResultSets;
    }
  }
  String javaReturnType=getJavaTypeName();
  MethodBuilder mbnc=null;
  MethodBuilder mbcm=mb;
  if (returnsNullOnNullState != null) {
    mbnc=acb.newGeneratedFun(javaReturnType,Modifier.PRIVATE,methodParameterTypes);
    Class[] throwsSet=((java.lang.reflect.Method)method).getExceptionTypes();
    for (int te=0; te < throwsSet.length; te++) {
      mbnc.addThrownException(throwsSet[te].getName());
    }
    mbnc.getField(returnsNullOnNullState);
    mbnc.conditionalIf();
    mbnc.pushNull(javaReturnType);
    mbnc.startElseCode();
    if (!actualMethodReturnType.equals(javaReturnType))     mbnc.pushNewStart(javaReturnType);
    for (int pa=0; pa < nargs; pa++) {
      mbnc.getParameter(pa);
    }
    mbcm=mbnc;
  }
  mbcm.callMethod(VMOpcode.INVOKESTATIC,method.getDeclaringClass().getName(),methodName,actualMethodReturnType,nargs);
  if (returnsNullOnNullState != null) {
    if (!actualMethodReturnType.equals(javaReturnType)) {
      if (actualMethodReturnType.equals("String_Node_Str") && javaReturnType.equals("String_Node_Str"))       mbnc.upCast("String_Node_Str");
      mbnc.pushNewComplete(1);
    }
    mbnc.completeConditional();
    mbnc.methodReturn();
    mbnc.complete();
    mb.callMethod(VMOpcode.INVOKEVIRTUAL,acb.getClassBuilder().getFullName(),mbnc.getName(),javaReturnType,nargs);
    mbnc=null;
  }
  if (routineInfo != null) {
    if (functionEntrySQLAllowed != null) {
      acb.pushThisAsActivation(mb);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.LanguageConnectionContext,0);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",0);
      mb.getField(functionEntrySQLAllowed);
      mb.push(true);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",2);
    }
    if (outParamArrays != null) {
      MethodBuilder constructor=acb.getConstructor();
      acb.pushThisAsActivation(constructor);
      constructor.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.ParameterValueSet,0);
      acb.pushThisAsActivation(mb);
      mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.ParameterValueSet,0);
      int[] parameterModes=routineInfo.getParameterModes();
      for (int i=0; i < outParamArrays.length; i++) {
        int parameterMode=parameterModes[getRoutineArgIdx(i)];
        if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {
          ValueNode sqlParamNode=((SQLToJavaValueNode)methodParms[i]).getSQLValueNode();
          int applicationParameterNumber=applicationParameterNumbers[i];
          constructor.dup();
          constructor.push(applicationParameterNumber);
          constructor.push(parameterMode);
          constructor.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",2);
          LocalField lf=outParamArrays[i];
          mb.dup();
          mb.push(applicationParameterNumber);
          mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str",ClassName.DataValueDescriptor,1);
          DataTypeDescriptor paramdtd=sqlParamNode.getTypeServices();
          boolean isNumericType=paramdtd.getTypeId().isNumericTypeId();
          boolean isAnsiUDT=paramdtd.getTypeId().getBaseTypeId().isAnsiUDT();
          Class cellType=((java.lang.reflect.Method)method).getParameterTypes()[getRoutineArgIdx(i)].getComponentType();
          if (isVararg(i)) {
            cellType=cellType.getComponentType();
          }
          boolean isPrimitive=cellType.isPrimitive();
          if (isNumericType) {
            if (!isPrimitive)             mb.cast(ClassName.NumberDataValue);
          }
 else           if (paramdtd.getTypeId().isBooleanTypeId()) {
            if (!isPrimitive)             mb.cast(ClassName.BooleanDataValue);
          }
          if (paramdtd.getTypeId().variableLength()) {
            mb.dup();
          }
          mb.getField(lf);
          mb.getArrayElement(0);
          if (isNumericType && !isPrimitive) {
            mb.upCast("String_Node_Str");
          }
          if (isAnsiUDT) {
            mb.upCast("String_Node_Str");
          }
          mb.callMethod(VMOpcode.INVOKEINTERFACE,null,"String_Node_Str","String_Node_Str",1);
          if (paramdtd.getTypeId().variableLength()) {
            mb.push(isNumericType ? paramdtd.getPrecision() : paramdtd.getMaximumWidth());
            mb.push(paramdtd.getScale());
            mb.push(isNumericType);
            mb.callMethod(VMOpcode.INVOKEINTERFACE,ClassName.VariableSizeDataValue,"String_Node_Str","String_Node_Str",3);
          }
        }
      }
      constructor.endStatement();
      mb.endStatement();
    }
  }
}