File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes A Strange behavior about Java Resource Bundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "A Strange behavior about Java Resource Bundle" Watch "A Strange behavior about Java Resource Bundle" New topic

A Strange behavior about Java Resource Bundle

Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
I am working in a project where I have to load two different property files (for example & ) which are totally have different base name and it should also have inheritance relationship between this two bundle. So that if any keys are not found in it should get from

When I was analyzing the resource bundle code, I came to know there is method setParent(), this method is used to set which is your parent bundle (something like java super class). For example if we use bundle name called "" the my parent bundle should be "".

As this method was protected method in ResourceBundle Class, so to use this class I have sub classed my own ResourceBundle class and overridden the setParent Method like below.

So after changing the class I have executed with the below method, excepts that it should pick the key from file if the key is not present in file.

As usual J there is an error thrown saying the key was missing.

So what's wrong?

I tried to debug the code in the resource bundle class and below code surprised me.

As I was setting the value in setParent() of resource bundle to change the parent resource bundle, but when the bundle are created using ResourceBundle.getInstance(), internally it calls getBundleImpl() which set the parent as "NOT_FOUND" direcly.

I was really confused why the code was setting directly rather than using values from the setter method???

As user of this class this implementation really stops customization which users expects.

Please feel free to comment.

My Thoughts :
Try not to become a man of success but rather to become a man of value.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46352
Moving thread as too difficult for "beginning Java"
I agree. Here's the link:
subject: A Strange behavior about Java Resource Bundle
It's not a secret anymore!