Avoid custom ResourceBundle.Control on Jigsaw (as far as possible)

Issue: SPR-16776
master
Juergen Hoeller 6 years ago
parent eaff2c28a7
commit d5aedac6db
  1. 18
      spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java

@ -220,8 +220,26 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException { protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException {
ClassLoader classLoader = getBundleClassLoader(); ClassLoader classLoader = getBundleClassLoader();
Assert.state(classLoader != null, "No bundle ClassLoader set"); Assert.state(classLoader != null, "No bundle ClassLoader set");
String defaultEncoding = getDefaultEncoding();
if ((defaultEncoding != null && !"ISO-8859-1".equals(defaultEncoding)) ||
!isFallbackToSystemLocale() || getCacheMillis() >= 0) {
try {
return ResourceBundle.getBundle(basename, locale, classLoader, new MessageSourceControl()); return ResourceBundle.getBundle(basename, locale, classLoader, new MessageSourceControl());
} }
catch (UnsupportedOperationException ex) {
// Probably in a Jigsaw environment on JDK 9+
throw new IllegalStateException(
"Custom ResourceBundleMessageSource configuration requires custom ResourceBundle.Control " +
"which is not supported in current system environment (e.g. JDK 9+ module path deployment): " +
"consider using defaults (ISO-8859-1 encoding, fallback to system locale, unlimited caching)",
ex);
}
}
else {
return ResourceBundle.getBundle(basename, locale, classLoader);
}
}
/** /**
* Load a property-based resource bundle from the given reader. * Load a property-based resource bundle from the given reader.

Loading…
Cancel
Save