Skip to content

Commit 163d346

Browse files
marko-bekhtagsmet
authored andcommitted
HV-1585 Added an early check if a message should be resolved or not
- Added a check to prevent map lookups in case of simple user defined message that does not require any message resolution and should not be stored in the cache.
1 parent df1fb57 commit 163d346

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ public String interpolate(String message, Context context, Locale locale) {
251251
* @return the interpolated message.
252252
*/
253253
private String interpolateMessage(String message, Context context, Locale locale) throws MessageDescriptorFormatException {
254+
// if the message does not contain any message parameter, we can ignore the next steps and just return
255+
// the unescaped message. It avoids storing the message in the cache and a cache lookup.
256+
if ( message.indexOf( '{' ) < 0 ) {
257+
return replaceEscapedLiterals( message );
258+
}
259+
254260
String resolvedMessage = null;
255261

256262
// either retrieve message from cache, or if message is not yet there or caching is disabled,
@@ -298,11 +304,6 @@ private List<Token> getParameterTokens(String resolvedMessage, ConcurrentReferen
298304
}
299305

300306
private String resolveMessage(String message, Locale locale) {
301-
//if message does not contain something like "{message.key}" we can ignore next steps and just return the message
302-
if ( message.indexOf( '{' ) < 0 ) {
303-
return message;
304-
}
305-
306307
String resolvedMessage = message;
307308

308309
ResourceBundle userResourceBundle = userResourceBundleLocator

0 commit comments

Comments
 (0)