ResourceBundle.getBundle() Question/Possible Bug?
I am trying to understand why ResourceBundle.getBundle() is working the way it is under a particular scenario. It looks like a bug to me, but I wanted to see if anyone else can shed some light on this.
My sample program sets up the default locale asen_US and then constructs a locale ofen_UK. I have defined the following resource bundle property files:
MessagesBundle_en_US.properties:
greetings = Hello.
farewell = Goodbye.
inquiry = How are you?
MessagesBundle.properties:
greetings = Hiya.
farewell = Seeya.
inquiry = How you doing?
When I run my sample program (and it attempts to get a resource bundle for en_UK - which does not exist), instead it ends up retrieving the 'root' bundle. I would have expected it to find the en_US bundle (since it is the default locale). In looking through the ResourceBundle.java source code I noticed that getBundleImpl() contains a break statement if the bundle names 'intersect' and this is why the root bundle is used.
Here is my sample program:
RBSample .java:
import java.util.*;
publicclass RBSample{
staticpublicvoid main(String[] args){
String language;
String country;
Locale.setDefault(new Locale("en","US"));
Locale currentLocale;
ResourceBundle messages;
currentLocale = Locale.UK;
System.out.println("currentLocale = " + currentLocale.getDisplayName());
messages =
ResourceBundle.getBundle("MessagesBundle",currentLocale);
Locale messagesLocale = messages.getLocale();
System.out.println("messagesLocale = " + messagesLocale.getDisplayName());
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
}
}
Sample Output:
currentLocale = English (United Kingdom)
messagesLocale =
Hiya.
How you doing?
Seeya.
Am I missing something here? Why is it behaving this way?

