public static Class < ? > getCallingClass ( ) { ClassContextSecurityManager securityManager = getSecurityManager ( ) ; if ( securityManager == null ) return null ; Class < ? > [ ] trace = securityManager . getClassContext ( ) ; String thisClassName = Util . class . getName ( ) ; // Advance until Util is found int i ; for ( i = 0 ; i < trace . length ; i ++ ) { if ( thisClassName . equals ( trace [ i ] . getName ( ) ) ) break ; } // trace[i] = Util; trace[i+1] = caller; trace[i+2] = caller's caller if ( i >= trace . length || i + 2 >= trace . length ) { throw new IllegalStateException ( "Failed to find org.slf4j.helpers.Util or its caller in the stack; " + "this should not happen" ) ; } return trace [ i + 2 ] ; }
Returns the name of the class which called the invoking method .