Program: 149732
Project: 149732
Buggy source:
/** 
 * GetFieldID:  return a field id, which can be cached in native code and reused
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the RVMClass object
 * @param fieldNameAddress a raw address to a null-terminated string in C for the field name
 * @param descriptorAddress a raw address to a null-terminated string in C for the descriptor
 * @return the fieldID of an instance field given the class, field nameand type. Return 0 if the field is not found
 * @exception NoSuchFieldError if the specified field cannot be found
 * @exception ExceptionInInitializerError if the class initializer fails
 * @exception OutOfMemoryError if the system runs out of memory
 */
private static int GetFieldID(JNIEnvironment env,int classJREF,Address fieldNameAddress,Address descriptorAddress){
  if (traceJNI)   VM.sysWrite("String_Node_Str");
  RuntimeEntrypoints.checkJNICountDownToGC();
  try {
    if (traceJNI)     VM.sysWriteln("String_Node_Str",classJREF);
    Class<?> cls=(Class<?>)env.getJNIRef(classJREF);
    if (VM.VerifyAssertions)     VM._assert(cls != null);
    String fieldString=JNIHelpers.createStringFromC(fieldNameAddress);
    Atom fieldName=Atom.findOrCreateAsciiAtom(fieldString);
    String descriptorString=JNIHelpers.createStringFromC(descriptorAddress);
    Atom descriptor=Atom.findOrCreateAsciiAtom(descriptorString);
    RVMField[] fields=java.lang.JikesRVMSupport.getTypeForClass(cls).getInstanceFields();
    for (    RVMField f : fields) {
      if (f.getName() == fieldName && f.getDescriptor() == descriptor) {
        return f.getId();
      }
    }
    env.recordException(new NoSuchFieldError(fieldString + "String_Node_Str" + descriptorString+ "String_Node_Str"+ cls));
    return 0;
  }
 catch (  Throwable unexpected) {
    if (traceJNI)     unexpected.printStackTrace(System.err);
    env.recordException(unexpected);
    return 0;
  }
}

Fixed version (ground truth):
/** 
 * GetFieldID:  return a field id, which can be cached in native code and reused
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the RVMClass object
 * @param fieldNameAddress a raw address to a null-terminated string in C for the field name
 * @param descriptorAddress a raw address to a null-terminated string in C for the descriptor
 * @return the fieldID of an instance field given the class, field nameand type. Return 0 if the field is not found
 * @exception NoSuchFieldError if the specified field cannot be found
 * @exception ExceptionInInitializerError if the class initializer fails
 * @exception OutOfMemoryError if the system runs out of memory
 */
private static int GetFieldID(JNIEnvironment env,int classJREF,Address fieldNameAddress,Address descriptorAddress){
  if (traceJNI)   VM.sysWrite("String_Node_Str");
  RuntimeEntrypoints.checkJNICountDownToGC();
  try {
    if (traceJNI)     VM.sysWriteln("String_Node_Str",classJREF);
    Class<?> cls=(Class<?>)env.getJNIRef(classJREF);
    if (VM.VerifyAssertions)     VM._assert(cls != null);
    String fieldString=JNIHelpers.createStringFromC(fieldNameAddress);
    Atom fieldName=Atom.findOrCreateAsciiAtom(fieldString);
    String descriptorString=JNIHelpers.createStringFromC(descriptorAddress);
    Atom descriptor=Atom.findOrCreateAsciiAtom(descriptorString);
    RVMField[] fields=java.lang.JikesRVMSupport.getTypeForClass(cls).getInstanceFields();
    for (int i=fields.length - 1; i >= 0; i--) {
      RVMField f=fields[i];
      if (f.getName() == fieldName && f.getDescriptor() == descriptor) {
        return f.getId();
      }
    }
    env.recordException(new NoSuchFieldError(fieldString + "String_Node_Str" + descriptorString+ "String_Node_Str"+ cls));
    return 0;
  }
 catch (  Throwable unexpected) {
    if (traceJNI)     unexpected.printStackTrace(System.err);
    env.recordException(unexpected);
    return 0;
  }
}