@@ -80,7 +80,8 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
80
80
* This allows for very efficient hash lookups, significantly faster
81
81
* than the ResourceBundle class's own cache.
82
82
*/
83
- private final Map <String , Map <Locale , ResourceBundle >> cachedResourceBundles = new ConcurrentHashMap <>();
83
+ private final Map <String , Map <Locale , ResourceBundle >> cachedResourceBundles =
84
+ new ConcurrentHashMap <>();
84
85
85
86
/**
86
87
* Cache to hold already generated MessageFormats.
@@ -90,7 +91,11 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
90
91
* very efficient hash lookups without concatenated keys.
91
92
* @see #getMessageFormat
92
93
*/
93
- private final Map <ResourceBundle , Map <String , Map <Locale , MessageFormat >>> cachedBundleMessageFormats = new ConcurrentHashMap <>();
94
+ private final Map <ResourceBundle , Map <String , Map <Locale , MessageFormat >>> cachedBundleMessageFormats =
95
+ new ConcurrentHashMap <>();
96
+
97
+ @ Nullable
98
+ private volatile MessageSourceControl control = new MessageSourceControl ();
94
99
95
100
96
101
/**
@@ -220,7 +225,24 @@ protected ResourceBundle getResourceBundle(String basename, Locale locale) {
220
225
protected ResourceBundle doGetBundle (String basename , Locale locale ) throws MissingResourceException {
221
226
ClassLoader classLoader = getBundleClassLoader ();
222
227
Assert .state (classLoader != null , "No bundle ClassLoader set" );
223
- return ResourceBundle .getBundle (basename , locale , classLoader , new MessageSourceControl ());
228
+
229
+ MessageSourceControl control = this .control ;
230
+ if (control != null ) {
231
+ try {
232
+ return ResourceBundle .getBundle (basename , locale , classLoader , control );
233
+ }
234
+ catch (UnsupportedOperationException ex ) {
235
+ // Probably in a Jigsaw environment on JDK 9+
236
+ this .control = null ;
237
+ if (logger .isInfoEnabled ()) {
238
+ logger .info ("ResourceBundle.Control not supported in current system environment: " +
239
+ ex .getMessage () + " - falling back to plain ResourceBundle.getBundle retrieval." );
240
+ }
241
+ }
242
+ }
243
+
244
+ // Fallback: plain getBundle lookup without Control handle
245
+ return ResourceBundle .getBundle (basename , locale , classLoader );
224
246
}
225
247
226
248
/**
@@ -266,7 +288,8 @@ protected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Loc
266
288
if (msg != null ) {
267
289
if (codeMap == null ) {
268
290
codeMap = new ConcurrentHashMap <>();
269
- Map <String , Map <Locale , MessageFormat >> existing = this .cachedBundleMessageFormats .putIfAbsent (bundle , codeMap );
291
+ Map <String , Map <Locale , MessageFormat >> existing =
292
+ this .cachedBundleMessageFormats .putIfAbsent (bundle , codeMap );
270
293
if (existing != null ) {
271
294
codeMap = existing ;
272
295
}
@@ -341,9 +364,9 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C
341
364
final String resourceName = toResourceName (bundleName , "properties" );
342
365
final ClassLoader classLoader = loader ;
343
366
final boolean reloadFlag = reload ;
344
- InputStream stream ;
367
+ InputStream inputStream ;
345
368
try {
346
- stream = AccessController .doPrivileged ((PrivilegedExceptionAction <InputStream >) () -> {
369
+ inputStream = AccessController .doPrivileged ((PrivilegedExceptionAction <InputStream >) () -> {
347
370
InputStream is = null ;
348
371
if (reloadFlag ) {
349
372
URL url = classLoader .getResource (resourceName );
@@ -364,12 +387,12 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C
364
387
catch (PrivilegedActionException ex ) {
365
388
throw (IOException ) ex .getException ();
366
389
}
367
- if (stream != null ) {
390
+ if (inputStream != null ) {
368
391
String encoding = getDefaultEncoding ();
369
392
if (encoding == null ) {
370
393
encoding = "ISO-8859-1" ;
371
394
}
372
- try (InputStreamReader bundleReader = new InputStreamReader (stream , encoding )) {
395
+ try (InputStreamReader bundleReader = new InputStreamReader (inputStream , encoding )) {
373
396
return loadBundle (bundleReader );
374
397
}
375
398
}
0 commit comments