Skip to content

Commit 2ed6f05

Browse files
committed
HV-1748 Remove preloadResourceBundles from PlatformResourceBundleLocator
1 parent 582db15 commit 2ed6f05

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

engine/src/main/java/org/hibernate/validator/internal/engine/AbstractConfigurationImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public final ConstraintValidatorFactory getDefaultConstraintValidatorFactory() {
576576
public final ResourceBundleLocator getDefaultResourceBundleLocator() {
577577
if ( defaultResourceBundleLocator == null ) {
578578
defaultResourceBundleLocator = new PlatformResourceBundleLocator(
579-
ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, preloadResourceBundles(), getAllSupportedLocales() );
579+
ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, preloadResourceBundles() ? getAllSupportedLocales() : Collections.emptySet() );
580580
}
581581

582582
return defaultResourceBundleLocator;
@@ -726,14 +726,12 @@ private MessageInterpolator getDefaultMessageInterpolatorConfiguredWithClassLoad
726726
if ( externalClassLoader != null ) {
727727
PlatformResourceBundleLocator userResourceBundleLocator = new PlatformResourceBundleLocator(
728728
ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES,
729-
preloadResourceBundles(),
730-
getAllSupportedLocales(),
729+
preloadResourceBundles() ? getAllSupportedLocales() : Collections.emptySet(),
731730
externalClassLoader
732731
);
733732
PlatformResourceBundleLocator contributorResourceBundleLocator = new PlatformResourceBundleLocator(
734733
ResourceBundleMessageInterpolator.CONTRIBUTOR_VALIDATION_MESSAGES,
735-
preloadResourceBundles(),
736-
getAllSupportedLocales(),
734+
preloadResourceBundles() ? getAllSupportedLocales() : Collections.emptySet(),
737735
externalClassLoader,
738736
true
739737
);

engine/src/main/java/org/hibernate/validator/messageinterpolation/AbstractMessageInterpolator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocat
280280

281281
if ( userResourceBundleLocator == null ) {
282282
this.userResourceBundleLocator = new PlatformResourceBundleLocator( USER_VALIDATION_MESSAGES,
283-
preloadResourceBundles, allLocalesToInitialize );
283+
allLocalesToInitialize );
284284
}
285285
else {
286286
this.userResourceBundleLocator = userResourceBundleLocator;
@@ -289,7 +289,6 @@ public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocat
289289
if ( contributorResourceBundleLocator == null ) {
290290
this.contributorResourceBundleLocator = new PlatformResourceBundleLocator(
291291
CONTRIBUTOR_VALIDATION_MESSAGES,
292-
preloadResourceBundles,
293292
allLocalesToInitialize,
294293
null,
295294
true
@@ -299,7 +298,7 @@ public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocat
299298
this.contributorResourceBundleLocator = contributorResourceBundleLocator;
300299
}
301300

302-
this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES, preloadResourceBundles, allLocalesToInitialize );
301+
this.defaultResourceBundleLocator = new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES, allLocalesToInitialize );
303302

304303
this.cachingEnabled = cacheMessages;
305304
if ( cachingEnabled ) {

engine/src/main/java/org/hibernate/validator/resourceloading/AggregateResourceBundleLocator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public AggregateResourceBundleLocator(List<String> bundleNames,
151151

152152
List<PlatformResourceBundleLocator> tmpBundleLocators = new ArrayList<>( bundleNames.size() );
153153
for ( String bundleName : bundleNames ) {
154-
tmpBundleLocators.add( new PlatformResourceBundleLocator( bundleName, preloadResourceBundles, localesToInitialize, classLoader ) );
154+
tmpBundleLocators
155+
.add( new PlatformResourceBundleLocator( bundleName, preloadResourceBundles ? localesToInitialize : Collections.emptySet(), classLoader ) );
155156
}
156157
this.resourceBundleLocators = CollectionHelper.toImmutableList( tmpBundleLocators );
157158
}

engine/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
*
4444
* @author Hardy Ferentschik
4545
* @author Gunnar Morling
46+
* @author Guillaume Smet
4647
*/
4748
public class PlatformResourceBundleLocator implements ResourceBundleLocator {
4849

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

56-
private final boolean preloadResourceBundles;
5757
@Immutable
5858
private final Map<Locale, ResourceBundle> preloadedResourceBundles;
5959

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

6969
/**
@@ -77,7 +77,7 @@ public PlatformResourceBundleLocator(String bundleName) {
7777
* @since 5.2
7878
*/
7979
public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader) {
80-
this( bundleName, false, Collections.emptySet(), classLoader );
80+
this( bundleName, Collections.emptySet(), classLoader );
8181
}
8282

8383
/**
@@ -92,46 +92,42 @@ public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader)
9292
* @since 5.2
9393
*/
9494
public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader, boolean aggregate) {
95-
this( bundleName, false, Collections.emptySet(), classLoader, aggregate );
95+
this( bundleName, Collections.emptySet(), classLoader, aggregate );
9696
}
9797

9898
/**
9999
* Creates a new {@link PlatformResourceBundleLocator}.
100100
*
101101
* @param bundleName the name of the bundle to load
102-
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
103102
* @param localesToInitialize the set of locales to initialize at bootstrap
104103
*
105104
* @since 6.1.1
106105
*/
107106
@Incubating
108-
public PlatformResourceBundleLocator(String bundleName, boolean preloadResourceBundles, Set<Locale> localesToInitialize) {
109-
this( bundleName, preloadResourceBundles, localesToInitialize, null );
107+
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize) {
108+
this( bundleName, localesToInitialize, null );
110109
}
111110

112111
/**
113112
* Creates a new {@link PlatformResourceBundleLocator}.
114113
*
115114
* @param bundleName the name of the bundle to load
116-
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
117115
* @param localesToInitialize the set of locales to initialize at bootstrap
118116
* @param classLoader the classloader to be used for loading the bundle. If {@code null}, the current thread context
119117
* classloader and finally Hibernate Validator's own classloader will be used for loading the specified
120118
* bundle.
121-
* @param preloadResourceBundles if resource bundles should be initialized when initializing the locator
122119
*
123120
* @since 6.1.1
124121
*/
125122
@Incubating
126-
public PlatformResourceBundleLocator(String bundleName, boolean preloadResourceBundles, Set<Locale> localesToInitialize, ClassLoader classLoader) {
127-
this( bundleName, preloadResourceBundles, localesToInitialize, classLoader, false );
123+
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize, ClassLoader classLoader) {
124+
this( bundleName, localesToInitialize, classLoader, false );
128125
}
129126

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

154149
this.aggregate = aggregate && RESOURCE_BUNDLE_CONTROL_INSTANTIABLE;
155150

156-
this.preloadResourceBundles = preloadResourceBundles;
157-
158-
if ( preloadResourceBundles ) {
159-
Contracts.assertNotEmpty( localesToInitialize, "localesToInitialize may not be empty if resource bundles have to be preloaded" );
160-
151+
if ( !localesToInitialize.isEmpty() ) {
161152
Map<Locale, ResourceBundle> tmpPreloadedResourceBundles = CollectionHelper.newHashMap( localesToInitialize.size() );
162153
for ( Locale localeToPreload : localesToInitialize ) {
163154
tmpPreloadedResourceBundles.put( localeToPreload, doGetResourceBundle( localeToPreload ) );
@@ -179,7 +170,7 @@ public PlatformResourceBundleLocator(String bundleName,
179170
*/
180171
@Override
181172
public ResourceBundle getResourceBundle(Locale locale) {
182-
if ( preloadResourceBundles ) {
173+
if ( !preloadedResourceBundles.isEmpty() ) {
183174
// we need to use containsKey() as the cached resource bundle can be null
184175
if ( preloadedResourceBundles.containsKey( locale ) ) {
185176
return preloadedResourceBundles.get( locale );

0 commit comments

Comments
 (0)