Program: 40535
Project: 40535
Buggy source:
/** 
 * TODO: clean this up. Create the IR for the synthetic method (e.g. Method.invoke)
 * @param method is something like Method.invoke or Construction.newInstance
 * @param target is the method being called reflectively
 */
private IR makeIR(IMethod method,IMethod target,ReceiverInstanceContext context){
  SpecializedMethod m=new SpecializedMethod(method,method.getDeclaringClass(),method.isStatic(),false);
  Map<Integer,ConstantValue> constants=HashMapFactory.make();
  int nextLocal=method.getNumberOfParameters() + 1;
  int nargs=target.getNumberOfParameters();
  int args[]=new int[nargs];
  int i=0;
  int pc=0;
  int parametersVn=-1;
  if (method.getReference().equals(CTOR_NEW_INSTANCE)) {
    TypeReference allocatedType=target.getDeclaringClass().getReference();
    m.addInstruction(allocatedType,new SSANewInstruction(args[i++]=nextLocal++,NewSiteReference.make(pc++,allocatedType)),true);
    parametersVn=2;
  }
 else {
    parametersVn=3;
    if (target.isStatic()) {
    }
 else {
      args[i++]=2;
    }
  }
  for (int j=i; j < nargs; j++) {
    int indexConst=nextLocal++;
    m.addInstruction(null,new SSAArrayLoadInstruction(args[i++]=nextLocal++,parametersVn,indexConst,TypeReference.JavaLangObject),false);
    constants.put(new Integer(indexConst),new ConstantValue(j - 1));
    pc++;
  }
  int exceptions=nextLocal++;
  int result=-1;
  if (method.getReference().equals(CTOR_NEW_INSTANCE)) {
    m.addInstruction(null,new SSAInvokeInstruction(args,exceptions,CallSiteReference.make(pc++,target.getReference(),IInvokeInstruction.Dispatch.SPECIAL)),false);
    m.addInstruction(null,new SSAReturnInstruction(args[0],false),false);
  }
 else {
    Dispatch d=target.isStatic() ? Dispatch.STATIC : Dispatch.VIRTUAL;
    if (target.getReturnType().equals(TypeReference.Void)) {
      m.addInstruction(null,new SSAInvokeInstruction(args,exceptions,CallSiteReference.make(pc++,target.getReference(),d)),false);
    }
 else {
      result=nextLocal++;
      m.addInstruction(null,new SSAInvokeInstruction(result,args,exceptions,CallSiteReference.make(pc++,target.getReference(),d)),false);
      m.addInstruction(null,new SSAReturnInstruction(result,false),false);
    }
  }
  SSAInstruction[] instrs=new SSAInstruction[m.allInstructions.size()];
  m.allInstructions.<SSAInstruction>toArray(instrs);
  return new SyntheticIR(method,context,new InducedCFG(instrs,method,context),instrs,SSAOptions.defaultOptions(),constants);
}

Fixed version (ground truth):
/** 
 * TODO: clean this up. Create the IR for the synthetic method (e.g. Method.invoke)
 * @param method is something like Method.invoke or Construction.newInstance
 * @param target is the method being called reflectively
 */
private IR makeIR(IMethod method,IMethod target,ReceiverInstanceContext context){
  SpecializedMethod m=new SpecializedMethod(method,method.getDeclaringClass(),method.isStatic(),false);
  Map<Integer,ConstantValue> constants=HashMapFactory.make();
  int nextLocal=method.getNumberOfParameters() + 1;
  int nargs=target.getNumberOfParameters();
  int args[]=new int[nargs];
  int pc=0;
  int parametersVn=-1;
  if (method.getReference().equals(CTOR_NEW_INSTANCE)) {
    TypeReference allocatedType=target.getDeclaringClass().getReference();
    m.addInstruction(allocatedType,new SSANewInstruction(args[0]=nextLocal++,NewSiteReference.make(pc++,allocatedType)),true);
    parametersVn=2;
  }
 else {
    parametersVn=3;
    if (target.isStatic()) {
    }
 else {
      args[0]=2;
    }
  }
  int nextArg=target.isStatic() ? 0 : 1;
  int nextParameter=0;
  for (int j=nextArg; j < nargs; j++) {
    int indexConst=nextLocal++;
    constants.put(new Integer(indexConst),new ConstantValue(nextParameter++));
    int temp=nextLocal++;
    m.addInstruction(null,new SSAArrayLoadInstruction(temp,parametersVn,indexConst,TypeReference.JavaLangObject),false);
    pc++;
    args[j]=nextLocal++;
    TypeReference type=target.getParameterType(j);
    SSACheckCastInstruction cast=SSAInstructionFactory.CheckCastInstruction(args[j],temp,type);
    m.addInstruction(null,cast,false);
    pc++;
  }
  int exceptions=nextLocal++;
  int result=-1;
  if (method.getReference().equals(CTOR_NEW_INSTANCE)) {
    m.addInstruction(null,new SSAInvokeInstruction(args,exceptions,CallSiteReference.make(pc++,target.getReference(),IInvokeInstruction.Dispatch.SPECIAL)),false);
    m.addInstruction(null,new SSAReturnInstruction(args[0],false),false);
  }
 else {
    Dispatch d=target.isStatic() ? Dispatch.STATIC : Dispatch.VIRTUAL;
    if (target.getReturnType().equals(TypeReference.Void)) {
      m.addInstruction(null,new SSAInvokeInstruction(args,exceptions,CallSiteReference.make(pc++,target.getReference(),d)),false);
    }
 else {
      result=nextLocal++;
      m.addInstruction(null,new SSAInvokeInstruction(result,args,exceptions,CallSiteReference.make(pc++,target.getReference(),d)),false);
      m.addInstruction(null,new SSAReturnInstruction(result,false),false);
    }
  }
  SSAInstruction[] instrs=new SSAInstruction[m.allInstructions.size()];
  m.allInstructions.<SSAInstruction>toArray(instrs);
  return new SyntheticIR(method,context,new InducedCFG(instrs,method,context),instrs,SSAOptions.defaultOptions(),constants);
}