Program: 149733
Project: 149733
Buggy source:
/** 
 * GetStaticFieldID:  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 offset of a static 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 GetStaticFieldID(JNIEnvironment env,int classJREF,Address fieldNameAddress,Address descriptorAddress){
  if (traceJNI)   VM.sysWrite("String_Node_Str");
  RuntimeEntrypoints.checkJNICountDownToGC();
  try {
    Class<?> cls=(Class<?>)env.getJNIRef(classJREF);
    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).getStaticFields();
    for (    RVMField field : fields) {
      if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
        return field.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):
/** 
 * GetStaticFieldID:  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 offset of a static 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 GetStaticFieldID(JNIEnvironment env,int classJREF,Address fieldNameAddress,Address descriptorAddress){
  if (traceJNI)   VM.sysWrite("String_Node_Str");
  RuntimeEntrypoints.checkJNICountDownToGC();
  try {
    Class<?> cls=(Class<?>)env.getJNIRef(classJREF);
    String fieldString=JNIHelpers.createStringFromC(fieldNameAddress);
    Atom fieldName=Atom.findOrCreateAsciiAtom(fieldString);
    String descriptorString=JNIHelpers.createStringFromC(descriptorAddress);
    Atom descriptor=Atom.findOrCreateAsciiAtom(descriptorString);
    RVMType rvmType=java.lang.JikesRVMSupport.getTypeForClass(cls);
    if (rvmType.isClassType()) {
      for (RVMClass curClass=rvmType.asClass(); curClass != null; curClass=curClass.getSuperClass()) {
        for (        RVMField field : curClass.getStaticFields()) {
          if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
            return field.getId();
          }
        }
      }
      for (      RVMClass curClass : rvmType.asClass().getAllImplementedInterfaces()) {
        for (        RVMField field : curClass.getStaticFields()) {
          if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
            return field.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;
  }
}