I'm experiencing some strange behavior when fetching messages with apostrophes surrounding argument usage from a resource bundle using Spring's ResourceBundleMessageSource. Specifically, the apostrophes seem to short-circuit the insertion of argument values into the message. The following are and example resource bundle file and a simplified version of the calling class:
application.properties:
ResourceServiceImpl:Code:message.0=Blah {1} {0} message.1=Blah {1} '{0}' message.2=Blah {1} \'{0}\' message.3=Blah {1} \\'{0}\\'
Now, assuming resourceService is a reference to an instance of ResourceServiceImpl and I call resourceService.getResoruce(...) once for each message as follows, I get very strange results:Code:public class ResourceServiceImpl extends BaseService implements ResourceService, InitializingBean { private ResourceBundleMessageSource messageSource; @Override public void afterPropertiesSet() throws Exception { Validate.notNull(messageSource); } public String getResource(String key, Object... params) throws RuntimeException { LanguageService service = serviceProvider.getLanguageService(); Locale locale = service.getSystemLocale(); return messageSource.getMessage(key, params, locale); } }
Calling code:
Result:Code:for (int i=0; i<4; i++) { System.out.println(resourceService.getMessage("message"+i, "arg0", "arg1"); }
So no combination of escape characters seems to do the trick either... Any ideas as to what is going on here?Code:Blah arg1 arg0 Blah arg1 {0} Blah arg1 {0} Blah arg1 \{0}\


Reply With Quote
