Program: 149863
Project: 149863
Buggy source:
/** 
 * Find the first non-VM method/exception initializer method in the stack trace. As we're working with the compiled methods we're assumig the constructor of the exception won't have been inlined into the throwing method.
 * @param cause the cause of generating the stack trace marking the end of theframes to elide
 * @return the index of the method throwing the exception or else 0
 */
private int firstRealMethod(Throwable cause){
  if (VM_Options.stackTraceFull) {
    return 0;
  }
 else {
    int element=0;
    VM_CompiledMethod compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
    if (cause instanceof OutOfMemoryError) {
      while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() != VM_Runtime.class) {
        element++;
        compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
      }
      while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == VM_Runtime.class) {
        element++;
        compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
      }
      return element;
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == VM_StackTrace.class) {
      element++;
      compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == java.lang.VMThrowable.class) {
      element++;
      compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == java.lang.Throwable.class) {
      element++;
      compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && (compiledMethod.getMethod().getDeclaringClass().getClassForType() != cause.getClass())&& compiledMethod.getMethod().isObjectInitializer()&& compiledMethod.getMethod().getDeclaringClass().isThrowable()) {
      element++;
      compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && (compiledMethod.getMethod().getDeclaringClass().getClassForType() == cause.getClass())&& compiledMethod.getMethod().isObjectInitializer()) {
      element++;
      compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element]);
    }
    if (element < compiledMethods.length - 2) {
      compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element + 1]);
      if ((compiledMethod != null) && compiledMethod.getCompilerType() == VM_CompiledMethod.TRAP) {
        element+=2;
        compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[element + 1]);
      }
    }
    return element;
  }
}

Fixed version (ground truth):
/** 
 * Find the first non-VM method/exception initializer method in the stack trace. As we're working with the compiled methods we're assumig the constructor of the exception won't have been inlined into the throwing method.
 * @param cause the cause of generating the stack trace marking the end of theframes to elide
 * @return the index of the method throwing the exception or else 0
 */
private int firstRealMethod(Throwable cause){
  if (VM_Options.stackTraceFull) {
    return 0;
  }
 else {
    int element=0;
    VM_CompiledMethod compiledMethod=getCompiledMethod(element);
    if (cause instanceof OutOfMemoryError) {
      while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() != VM_Runtime.class) {
        element++;
        compiledMethod=getCompiledMethod(element);
      }
      while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == VM_Runtime.class) {
        element++;
        compiledMethod=getCompiledMethod(element);
      }
      return element;
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == VM_StackTrace.class) {
      element++;
      compiledMethod=getCompiledMethod(element);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == java.lang.VMThrowable.class) {
      element++;
      compiledMethod=getCompiledMethod(element);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && compiledMethod.getMethod().getDeclaringClass().getClassForType() == java.lang.Throwable.class) {
      element++;
      compiledMethod=getCompiledMethod(element);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && (compiledMethod.getMethod().getDeclaringClass().getClassForType() != cause.getClass())&& compiledMethod.getMethod().isObjectInitializer()&& compiledMethod.getMethod().getDeclaringClass().isThrowable()) {
      element++;
      compiledMethod=getCompiledMethod(element);
    }
    while ((element < compiledMethods.length) && (compiledMethod != null) && (compiledMethod.getMethod().getDeclaringClass().getClassForType() == cause.getClass())&& compiledMethod.getMethod().isObjectInitializer()) {
      element++;
      compiledMethod=getCompiledMethod(element);
    }
    if (element < compiledMethods.length - 2) {
      compiledMethod=getCompiledMethod(element + 1);
      if ((compiledMethod != null) && compiledMethod.getCompilerType() == VM_CompiledMethod.TRAP) {
        element+=2;
      }
    }
    return element;
  }
}