Skip to content

Commit

Permalink
HV-1748 Remove preloadResourceBundles from PlatformResourceBundleLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Jan 15, 2020
1 parent 582db15 commit 2ed6f05
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
Expand Up @@ -576,7 +576,7 @@ public final ConstraintValidatorFactory getDefaultConstraintValidatorFactory() {
public final ResourceBundleLocator getDefaultResourceBundleLocator() {
if ( defaultResourceBundleLocator == null ) {
defaultResourceBundleLocator = new PlatformResourceBundleLocator(
ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, preloadResourceBundles(), getAllSupportedLocales() );
ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, preloadResourceBundles() ? getAllSupportedLocales() : Collections.emptySet() );
}

return defaultResourceBundleLocator;
Expand Down Expand Up @@ -726,14 +726,12 @@ private MessageInterpolator getDefaultMessageInterpolatorConfiguredWithClassLoad
if ( externalClassLoader != null ) {
PlatformResourceBundleLocator userResourceBundleLocator = new PlatformResourceBundleLocator(
ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES,
preloadResourceBundles(),
getAllSupportedLocales(),
preloadResourceBundles() ? getAllSupportedLocales() : Collections.emptySet(),
externalClassLoader
);
PlatformResourceBundleLocator contributorResourceBundleLocator = new PlatformResourceBundleLocator(
ResourceBundleMessageInterpolator.CONTRIBUTOR_VALIDATION_MESSAGES,
preloadResourceBundles(),
getAllSupportedLocales(),
preloadResourceBundles() ? getAllSupportedLocales() : Collections.emptySet(),
externalClassLoader,
true
);
Expand Down
Expand Up @@ -280,7 +280,7 @@ public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocat

if ( userResourceBundleLocator == null ) {
this.userResourceBundleLocator = new PlatformResourceBundleLocator( USER_VALIDATION_MESSAGES,
preloadResourceBundles, allLocalesToInitialize );
allLocalesToInitialize );
}
else {
this.userResourceBundleLocator = userResourceBundleLocator;
Expand All @@ -289,7 +289,6 @@ public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocat
if ( contributorResourceBundleLocator == null ) {
this.contributorResourceBundleLocator = new PlatformResourceBundleLocator(
CONTRIBUTOR_VALIDATION_MESSAGES,
preloadResourceBundles,
allLocalesToInitialize,
null,
true
Expand All @@ -299,7 +298,7 @@ public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocat
this.contributorResourceBundleLocator = contributorResourceBundleLocator;
}

this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES, preloadResourceBundles, allLocalesToInitialize );
this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES, allLocalesToInitialize );

this.cachingEnabled = cacheMessages;
if ( cachingEnabled ) {
Expand Down
Expand Up @@ -151,7 +151,8 @@ public AggregateResourceBundleLocator(List<String> bundleNames,

List<PlatformResourceBundleLocator> tmpBundleLocators = new ArrayList<>( bundleNames.size() );
for ( String bundleName : bundleNames ) {
tmpBundleLocators.add( new PlatformResourceBundleLocator( bundleName, preloadResourceBundles, localesToInitialize, classLoader ) );
tmpBundleLocators
.add( new PlatformResourceBundleLocator( bundleName, preloadResourceBundles ? localesToInitialize : Collections.emptySet(), classLoader ) );
}
this.resourceBundleLocators = CollectionHelper.toImmutableList( tmpBundleLocators );
}
Expand Down
Expand Up @@ -43,6 +43,7 @@
*
* @author Hardy Ferentschik
* @author Gunnar Morling
* @author Guillaume Smet
*/
public class PlatformResourceBundleLocator implements ResourceBundleLocator {

Expand All @@ -53,7 +54,6 @@ public class PlatformResourceBundleLocator implements ResourceBundleLocator {
private final ClassLoader classLoader;
private final boolean aggregate;

private final boolean preloadResourceBundles;
@Immutable
private final Map<Locale, ResourceBundle> preloadedResourceBundles;

Expand All @@ -63,7 +63,7 @@ public class PlatformResourceBundleLocator implements ResourceBundleLocator {
* @param bundleName the name of the bundle to load
*/
public PlatformResourceBundleLocator(String bundleName) {
this( bundleName, false, Collections.emptySet() );
this( bundleName, Collections.emptySet() );
}

/**
Expand All @@ -77,7 +77,7 @@ public PlatformResourceBundleLocator(String bundleName) {
* @since 5.2
*/
public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader) {
this( bundleName, false, Collections.emptySet(), classLoader );
this( bundleName, Collections.emptySet(), classLoader );
}

/**
Expand All @@ -92,46 +92,42 @@ public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader)
* @since 5.2
*/
public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader, boolean aggregate) {
this( bundleName, false, Collections.emptySet(), classLoader, aggregate );
this( bundleName, Collections.emptySet(), classLoader, aggregate );
}

/**
* Creates a new {@link PlatformResourceBundleLocator}.
*
* @param bundleName the name of the bundle to load
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
* @param localesToInitialize the set of locales to initialize at bootstrap
*
* @since 6.1.1
*/
@Incubating
public PlatformResourceBundleLocator(String bundleName, boolean preloadResourceBundles, Set<Locale> localesToInitialize) {
this( bundleName, preloadResourceBundles, localesToInitialize, null );
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize) {
this( bundleName, localesToInitialize, null );
}

/**
* Creates a new {@link PlatformResourceBundleLocator}.
*
* @param bundleName the name of the bundle to load
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
* @param localesToInitialize the set of locales to initialize at bootstrap
* @param classLoader the classloader to be used for loading the bundle. If {@code null}, the current thread context
* classloader and finally Hibernate Validator's own classloader will be used for loading the specified
* bundle.
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
*
* @since 6.1.1
*/
@Incubating
public PlatformResourceBundleLocator(String bundleName, boolean preloadResourceBundles, Set<Locale> localesToInitialize, ClassLoader classLoader) {
this( bundleName, preloadResourceBundles, localesToInitialize, classLoader, false );
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize, ClassLoader classLoader) {
this( bundleName, localesToInitialize, classLoader, false );
}

/**
* Creates a new {@link PlatformResourceBundleLocator}.
*
* @param bundleName the name of the bundle to load
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
* @param localesToInitialize the set of locales to initialize at bootstrap
* @param classLoader the classloader to be used for loading the bundle. If {@code null}, the current thread context
* classloader and finally Hibernate Validator's own classloader will be used for loading the specified
Expand All @@ -142,7 +138,6 @@ public PlatformResourceBundleLocator(String bundleName, boolean preloadResourceB
*/
@Incubating
public PlatformResourceBundleLocator(String bundleName,
boolean preloadResourceBundles,
Set<Locale> localesToInitialize,
ClassLoader classLoader,
boolean aggregate) {
Expand All @@ -153,11 +148,7 @@ public PlatformResourceBundleLocator(String bundleName,

this.aggregate = aggregate && RESOURCE_BUNDLE_CONTROL_INSTANTIABLE;

this.preloadResourceBundles = preloadResourceBundles;

if ( preloadResourceBundles ) {
Contracts.assertNotEmpty( localesToInitialize, "localesToInitialize may not be empty if resource bundles have to be preloaded" );

if ( !localesToInitialize.isEmpty() ) {
Map<Locale, ResourceBundle> tmpPreloadedResourceBundles = CollectionHelper.newHashMap( localesToInitialize.size() );
for ( Locale localeToPreload : localesToInitialize ) {
tmpPreloadedResourceBundles.put( localeToPreload, doGetResourceBundle( localeToPreload ) );
Expand All @@ -179,7 +170,7 @@ public PlatformResourceBundleLocator(String bundleName,
*/
@Override
public ResourceBundle getResourceBundle(Locale locale) {
if ( preloadResourceBundles ) {
if ( !preloadedResourceBundles.isEmpty() ) {
// we need to use containsKey() as the cached resource bundle can be null
if ( preloadedResourceBundles.containsKey( locale ) ) {
return preloadedResourceBundles.get( locale );
Expand Down

0 comments on commit 2ed6f05

Please sign in to comment.