wood burning stoves 2.0*
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


Win a copy of Spring in Action this week in the Spring forum!
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
Author

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 parent.properties & child.properties ) 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 child.properties it should get from parent.properties.

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 "child_en.properties" the my parent bundle should be "child.properties".

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 parent.properties file if the key is not present in child.properties 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 : http://passion4java.blogspot.com
Try not to become a man of success but rather to become a man of value.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Moving thread as too difficult for "beginning Java"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Strange behavior about Java Resource Bundle