private ResourceBundle locateBundleFromCallee ( ) { ResourceBundle rb = null ; if ( finder == null ) { finder = StackFinder . getInstance ( ) ; } final Class < ? > aClass = finder . getCaller ( ) ; if ( aClass != null ) { // If aClass is NOT null (it was passed in, or we found it), // use its classloader first to try loading the resource // bundle ClassLoader classLoader = null ; try { classLoader = AccessController . doPrivileged ( new PrivilegedExceptionAction < ClassLoader > ( ) { public ClassLoader run ( ) throws Exception { return aClass . getClassLoader ( ) ; } } ) ; } catch ( PrivilegedActionException e ) { // convert to a runtime exception since callers already have // to deal // with that type throw new java . lang . RuntimeException ( e . getMessage ( ) ) ; } try { rb = ResourceBundle . getBundle ( ivBundleName , ivLocale , classLoader ) ; } catch ( RuntimeException re ) { // if (quiet) { // // logger.log(Level.FINEST, // "Unable to load {0} from {1} (from class {2}) in {3}; caught exception: {4}", // new Object[] { ivBundleName, classLoader, aClass, ivLocale, // re }); // } } // } else { // if (quiet) { // // logger.log(Level.FINEST, "Unable to load {0} class was null", new // Object[] { ivBundleName }); // } } return rb ; }
Call the stack finder to get the callee of the logging api then use the classloader from class to retrieve resource bundle