Skip to content

Commit d5aedac

Browse files
committed
Avoid custom ResourceBundle.Control on Jigsaw (as far as possible)
Issue: SPR-16776
1 parent eaff2c2 commit d5aedac

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,25 @@ protected ResourceBundle getResourceBundle(String basename, Locale locale) {
220220
protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException {
221221
ClassLoader classLoader = getBundleClassLoader();
222222
Assert.state(classLoader != null, "No bundle ClassLoader set");
223-
return ResourceBundle.getBundle(basename, locale, classLoader, new MessageSourceControl());
223+
String defaultEncoding = getDefaultEncoding();
224+
225+
if ((defaultEncoding != null && !"ISO-8859-1".equals(defaultEncoding)) ||
226+
!isFallbackToSystemLocale() || getCacheMillis() >= 0) {
227+
try {
228+
return ResourceBundle.getBundle(basename, locale, classLoader, new MessageSourceControl());
229+
}
230+
catch (UnsupportedOperationException ex) {
231+
// Probably in a Jigsaw environment on JDK 9+
232+
throw new IllegalStateException(
233+
"Custom ResourceBundleMessageSource configuration requires custom ResourceBundle.Control " +
234+
"which is not supported in current system environment (e.g. JDK 9+ module path deployment): " +
235+
"consider using defaults (ISO-8859-1 encoding, fallback to system locale, unlimited caching)",
236+
ex);
237+
}
238+
}
239+
else {
240+
return ResourceBundle.getBundle(basename, locale, classLoader);
241+
}
224242
}
225243

226244
/**

0 commit comments

Comments
 (0)