protected ResourceBundle getResourceBundle ( String basename , Locale locale ) { if ( this . cacheMillis >= 0 ) { // Fresh ResourceBundle.getBundle call in order to let ResourceBundle // do its native caching, at the expense of more extensive lookup steps. return doGetBundle ( basename , locale ) ; } else { // Cache forever: prefer locale cache over repeated getBundle calls. Map < Locale , ResourceBundle > localeMap = this . cachedResourceBundles . get ( basename ) ; if ( localeMap != null ) { ResourceBundle bundle = localeMap . get ( locale ) ; if ( bundle != null ) { return bundle ; } } try { ResourceBundle bundle = doGetBundle ( basename , locale ) ; if ( localeMap == null ) { localeMap = new ConcurrentHashMap <> ( ) ; Map < Locale , ResourceBundle > existing = this . cachedResourceBundles . putIfAbsent ( basename , localeMap ) ; if ( existing != null ) { localeMap = existing ; } } localeMap . put ( locale , bundle ) ; return bundle ; } catch ( MissingResourceException ex ) { log . warn ( "ResourceBundle [" + basename + "] not found for MessageSource: " + ex . getMessage ( ) ) ; // Assume bundle not found // -> do NOT throw the exception to allow for checking parent message source. return null ; } } }
Return a ResourceBundle for the given basename and code fetching already generated MessageFormats from the cache .