Program: 186587
Project: 186587
Buggy source:
private Method replace(Method method){
  MethodGen mg=new MethodGen(method,clazz.getClassName(),cpoolgen);
  InstructionList il=mg.getInstructionList();
  InstructionFinder f=new InstructionFinder(il);
  String methodId=method.getName() + method.getSignature();
  OldMethodInfo mi=getCli().getMethodInfo(methodId);
  String invokeStr="String_Node_Str";
  for (Iterator i=f.search(invokeStr); i.hasNext(); ) {
    InstructionHandle[] match=(InstructionHandle[])i.next();
    InstructionHandle first=match[0];
    InvokeInstruction ii=(InvokeInstruction)first.getInstruction();
    if (ii.getClassName(cpoolgen).equals(JOPizer.nativeClass)) {
      short opid=(short)JopInstr.getNative(ii.getMethodName(cpoolgen));
      if (opid == -1) {
        System.err.println(method.getName() + "String_Node_Str" + ii.getMethodName(cpoolgen)+ "String_Node_Str");
        first.setInstruction(new NOP());
      }
 else {
        first.setInstruction(new NativeInstruction(opid,(short)1));
        ((JOPizer)ai).outTxt.println("String_Node_Str" + first.getPosition());
        if (JOPizer.dumpMgci) {
          il.setPositions();
          int pc=first.getPosition();
          GCRTMethodInfo.removePC(pc + 2,mi);
          GCRTMethodInfo.removePC(pc + 1,mi);
        }
      }
    }
    if (ii instanceof INVOKESPECIAL) {
      if (!ii.getMethodName(cpoolgen).equals("String_Node_Str")) {
        if (!getCli().clazz.getClassName().equals(ii.getClassName(cpoolgen))) {
          Integer idx=new Integer(ii.getIndex());
          int new_index=getCli().cpoolUsed.indexOf(idx) + 1;
          first.setInstruction(new JOPSYS_INVOKESUPER((short)new_index));
        }
      }
    }
  }
  if (JOPizer.CACHE_INVAL) {
    f=new InstructionFinder(il);
    String fieldInstr="String_Node_Str";
    for (Iterator i=f.search(fieldInstr); i.hasNext(); ) {
      InstructionHandle[] match=(InstructionHandle[])i.next();
      InstructionHandle ih=match[0];
      FieldInstruction fi=(FieldInstruction)ih.getInstruction();
      JavaClass jc=JOPizer.jz.cliMap.get(fi.getClassName(cpoolgen)).clazz;
      Field field=null;
      while (field == null) {
        Field[] fields=jc.getFields();
        for (int k=0; k < fields.length; k++) {
          if (fields[k].getName().equals(fi.getFieldName(cpoolgen))) {
            field=fields[k];
            break;
          }
        }
        if (field == null) {
          try {
            jc=jc.getSuperClass();
          }
 catch (          ClassNotFoundException e) {
            e.printStackTrace();
            throw new Error();
          }
        }
      }
      if (field.isVolatile()) {
        if (field.getType().getSize() < 2) {
          if (fi instanceof GETFIELD || fi instanceof GETSTATIC) {
            ih.setInstruction(new InvalidateInstruction());
            ih=il.append(ih,fi);
          }
        }
 else {
          ih.setInstruction(new ACONST_NULL());
          ih=il.append(ih,new MONITORENTER());
          ih=il.append(ih,fi);
          ih=il.append(ih,new ACONST_NULL());
          ih=il.append(ih,new MONITOREXIT());
        }
      }
    }
  }
  f=new InstructionFinder(il);
  String cpInstr="String_Node_Str";
  for (Iterator it=f.search(cpInstr); it.hasNext(); ) {
    InstructionHandle[] match=(InstructionHandle[])it.next();
    InstructionHandle ih=match[0];
    CPInstruction cpii=(CPInstruction)ih.getInstruction();
    int index=cpii.getIndex();
    FieldInstruction fi=null;
    Type ft=null;
    if (cpii instanceof FieldInstruction) {
      fi=(FieldInstruction)ih.getInstruction();
      ft=fi.getFieldType(cpoolgen);
    }
    Integer idx=new Integer(index);
    int pos=getCli().cpoolUsed.indexOf(idx);
    int new_index=pos + 1;
    if (cpii instanceof GETFIELD || cpii instanceof PUTFIELD || cpii instanceof GETSTATIC|| cpii instanceof PUTSTATIC) {
      new_index=getFieldOffset(cp,index);
    }
 else {
      if (pos == -1) {
        System.out.println("String_Node_Str" + index + "String_Node_Str"+ cpoolgen.getConstant(index)+ "String_Node_Str");
        System.out.println("String_Node_Str" + getCli().cpoolUsed);
        System.out.println("String_Node_Str" + cpoolgen);
        System.exit(-1);
      }
    }
    cpii.setIndex(new_index);
    if (cpii instanceof FieldInstruction) {
      boolean isRef=ft instanceof ReferenceType;
      boolean isLong=ft == BasicType.LONG || ft == BasicType.DOUBLE;
      if (fi instanceof GETSTATIC) {
        if (isRef) {
          ih.setInstruction(new GETSTATIC_REF((short)new_index));
        }
 else         if (isLong) {
          ih.setInstruction(new GETSTATIC_LONG((short)new_index));
        }
      }
 else       if (fi instanceof PUTSTATIC) {
        if (isRef) {
          if (!com.jopdesign.build.JOPizer.USE_RTTM) {
            ih.setInstruction(new PUTSTATIC_REF((short)new_index));
          }
        }
 else         if (isLong) {
          ih.setInstruction(new PUTSTATIC_LONG((short)new_index));
        }
      }
 else       if (fi instanceof GETFIELD) {
        if (isRef) {
          ih.setInstruction(new GETFIELD_REF((short)new_index));
        }
 else         if (isLong) {
          ih.setInstruction(new GETFIELD_LONG((short)new_index));
        }
      }
 else       if (fi instanceof PUTFIELD) {
        if (isRef) {
          if (!com.jopdesign.build.JOPizer.USE_RTTM) {
            ih.setInstruction(new PUTFIELD_REF((short)new_index));
          }
        }
 else         if (isLong) {
          ih.setInstruction(new PUTFIELD_LONG((short)new_index));
        }
      }
    }
  }
  Method m=mg.getMethod();
  il.dispose();
  return m;
}

Fixed version (ground truth):
private Method replace(Method method){
  MethodGen mg=new MethodGen(method,clazz.getClassName(),cpoolgen);
  InstructionList il=mg.getInstructionList();
  InstructionFinder f=new InstructionFinder(il);
  String methodId=method.getName() + method.getSignature();
  OldMethodInfo mi=getCli().getMethodInfo(methodId);
  String invokeStr="String_Node_Str";
  for (Iterator i=f.search(invokeStr); i.hasNext(); ) {
    InstructionHandle[] match=(InstructionHandle[])i.next();
    InstructionHandle first=match[0];
    InvokeInstruction ii=(InvokeInstruction)first.getInstruction();
    if (ii.getClassName(cpoolgen).equals(JOPizer.nativeClass)) {
      short opid=(short)JopInstr.getNative(ii.getMethodName(cpoolgen));
      if (opid == -1) {
        System.err.println(method.getName() + "String_Node_Str" + ii.getMethodName(cpoolgen)+ "String_Node_Str");
        first.setInstruction(new NOP());
      }
 else {
        first.setInstruction(new NativeInstruction(opid,(short)1));
        ((JOPizer)ai).outTxt.println("String_Node_Str" + first.getPosition());
        if (JOPizer.dumpMgci) {
          il.setPositions();
          int pc=first.getPosition();
          GCRTMethodInfo.removePC(pc + 2,mi);
          GCRTMethodInfo.removePC(pc + 1,mi);
        }
      }
    }
    if (ii instanceof INVOKESPECIAL) {
      if (!ii.getMethodName(cpoolgen).equals("String_Node_Str")) {
        boolean isSuper=false;
        String declaredType=ii.getClassName(cpoolgen);
        JopClassInfo cls=getCli();
        OldClassInfo superClass=cls.superClass;
        while (superClass != null) {
          if (superClass.clazz.getClassName().equals(declaredType)) {
            isSuper=true;
            break;
          }
          if ("String_Node_Str".equals(superClass.clazz.getClassName())) {
            break;
          }
          superClass=superClass.superClass;
        }
        if (isSuper) {
          Integer idx=ii.getIndex();
          int new_index=getCli().cpoolUsed.indexOf(idx) + 1;
          first.setInstruction(new JOPSYS_INVOKESUPER((short)new_index));
        }
      }
    }
  }
  if (JOPizer.CACHE_INVAL) {
    f=new InstructionFinder(il);
    String fieldInstr="String_Node_Str";
    for (Iterator i=f.search(fieldInstr); i.hasNext(); ) {
      InstructionHandle[] match=(InstructionHandle[])i.next();
      InstructionHandle ih=match[0];
      FieldInstruction fi=(FieldInstruction)ih.getInstruction();
      JavaClass jc=JOPizer.jz.cliMap.get(fi.getClassName(cpoolgen)).clazz;
      Field field=null;
      while (field == null) {
        Field[] fields=jc.getFields();
        for (int k=0; k < fields.length; k++) {
          if (fields[k].getName().equals(fi.getFieldName(cpoolgen))) {
            field=fields[k];
            break;
          }
        }
        if (field == null) {
          try {
            jc=jc.getSuperClass();
          }
 catch (          ClassNotFoundException e) {
            e.printStackTrace();
            throw new Error();
          }
        }
      }
      if (field.isVolatile()) {
        if (field.getType().getSize() < 2) {
          if (fi instanceof GETFIELD || fi instanceof GETSTATIC) {
            ih.setInstruction(new InvalidateInstruction());
            ih=il.append(ih,fi);
          }
        }
 else {
          ih.setInstruction(new ACONST_NULL());
          ih=il.append(ih,new MONITORENTER());
          ih=il.append(ih,fi);
          ih=il.append(ih,new ACONST_NULL());
          ih=il.append(ih,new MONITOREXIT());
        }
      }
    }
  }
  f=new InstructionFinder(il);
  String cpInstr="String_Node_Str";
  for (Iterator it=f.search(cpInstr); it.hasNext(); ) {
    InstructionHandle[] match=(InstructionHandle[])it.next();
    InstructionHandle ih=match[0];
    CPInstruction cpii=(CPInstruction)ih.getInstruction();
    int index=cpii.getIndex();
    FieldInstruction fi=null;
    Type ft=null;
    if (cpii instanceof FieldInstruction) {
      fi=(FieldInstruction)ih.getInstruction();
      ft=fi.getFieldType(cpoolgen);
    }
    Integer idx=new Integer(index);
    int pos=getCli().cpoolUsed.indexOf(idx);
    int new_index=pos + 1;
    if (cpii instanceof GETFIELD || cpii instanceof PUTFIELD || cpii instanceof GETSTATIC|| cpii instanceof PUTSTATIC) {
      new_index=getFieldOffset(cp,index);
    }
 else {
      if (pos == -1) {
        System.out.println("String_Node_Str" + index + "String_Node_Str"+ cpoolgen.getConstant(index)+ "String_Node_Str");
        System.out.println("String_Node_Str" + getCli().cpoolUsed);
        System.out.println("String_Node_Str" + cpoolgen);
        System.exit(-1);
      }
    }
    cpii.setIndex(new_index);
    if (cpii instanceof FieldInstruction) {
      boolean isRef=ft instanceof ReferenceType;
      boolean isLong=ft == BasicType.LONG || ft == BasicType.DOUBLE;
      if (fi instanceof GETSTATIC) {
        if (isRef) {
          ih.setInstruction(new GETSTATIC_REF((short)new_index));
        }
 else         if (isLong) {
          ih.setInstruction(new GETSTATIC_LONG((short)new_index));
        }
      }
 else       if (fi instanceof PUTSTATIC) {
        if (isRef) {
          if (!com.jopdesign.build.JOPizer.USE_RTTM) {
            ih.setInstruction(new PUTSTATIC_REF((short)new_index));
          }
        }
 else         if (isLong) {
          ih.setInstruction(new PUTSTATIC_LONG((short)new_index));
        }
      }
 else       if (fi instanceof GETFIELD) {
        if (isRef) {
          ih.setInstruction(new GETFIELD_REF((short)new_index));
        }
 else         if (isLong) {
          ih.setInstruction(new GETFIELD_LONG((short)new_index));
        }
      }
 else       if (fi instanceof PUTFIELD) {
        if (isRef) {
          if (!com.jopdesign.build.JOPizer.USE_RTTM) {
            ih.setInstruction(new PUTFIELD_REF((short)new_index));
          }
        }
 else         if (isLong) {
          ih.setInstruction(new PUTFIELD_LONG((short)new_index));
        }
      }
    }
  }
  Method m=mg.getMethod();
  il.dispose();
  return m;
}