Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Strange behavior about Java Resource Bundle

 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50215
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving thread as too difficult for "beginning Java"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic