If one has a 'custom' (or delegate) ResourceBundle - that is, one that extends java.util.ResourceBundle, numeric parameters to property strings come as null.
This may apply to all non-string parameters.
A workaround is to 'stringify' parameters before calling the bundle.
eg.) Some ResourceBundle that is not a true PropertyResourceBundle (can't extend it):
public class CustomBundle extends ResourceBundle {
ResourceBundle rb;
public CustomBundle(ResourceBundle propertyBundle) {
this.rb = propertyBundle;
}
protected Object handleGetObject(String key) {
return rb.getString(key);
}
public Enumeration<String> getKeys() {
return this.rb.getKeys();
}
}
And the wrapped ResourceBundle (a true property file) has a property like:
property.key=This property has {0} parameters.
if we provide FreeMarker with one of these bundles and an Integer object named "param", the following throws a NullPointerExeption:
${bundleObj("property.key", param)}
The following prevents the exception, but the parameter comes out as null:
${bundleObj("property.key", param.string)}
The following is a workaround - stringify any such parameter first on the template:
<#assign stringCount = "${integerCount}">
${bundleObj("property.key", stringCount)}
ResourceBundle instances obtained from ResourceBundle.getBundle() are not affected.
Just want to clarify as I am newbie in this.
I need to create template to stringify parameter other than string
Created class customResourceBuilder which stringify all parameter passed to it.