/** * Retrieve the calling class of a method in this class. * * @return the calling class of a method in this class, or this class if no * other class could be determined. */ private static Class<?> getCaller() { Class<?> result = ResourceUtil.class; Class<?>[] callStack = CallerResolver.INSTANCE.getClassContext(); if (callStack.length > 0) { int index = 0; // look for the first class on the stack that isn't this class or the // inner utility class (it's most likely stack[2], but we don't want to // count on that and find out it isn't) while (index < callStack.length && (result == ResourceUtil.class || result == CallerResolver.class)) { result = callStack[index]; index = index + 1; } } return result; }