/** * Return the StackTraceElement at the given offset from this method * invocation. * * @param offset * @return a StackTraceElement */ public static StackTraceElement getCaller(final int offset) { final StackTraceElement[] stes = Thread.currentThread().getStackTrace(); StackTraceElement callerSTE = null; for (int i = 0; i < stes.length - offset - 1; i++) { if (stes[i].getClassName().equals(NullCheckingUtil.class.getName()) && stes[i].getMethodName().equals("getCaller")) { callerSTE = stes[i + 1 + offset]; break; } } badStateIfNull(callerSTE, "Ouch! Can't get the stack trace back to the caller of this method!"); return callerSTE; }
/** * Return the StackTraceElement at the given offset from this method * invocation. * * @param offset * @return a StackTraceElement */ public static StackTraceElement getCaller(final int offset) { final StackTraceElement[] stes = Thread.currentThread().getStackTrace(); StackTraceElement callerSTE = null; for (int i = 0; i < stes.length - offset - 1; i++) { if (stes[i].getClassName().equals(NullCheckingUtil.class.getName()) && stes[i].getMethodName().equals("getCaller")) { callerSTE = stes[i + 1 + offset]; break; } } badStateIfNull(callerSTE, "Ouch! Can't get the stack trace back to the caller of this method!"); return callerSTE; }