Seam - Load i18n Messages From Database

In some of the JavaEE web applications, it might be a requirement for you, to load internationalization (i18n) messages from database, instead of the usual way of using 'Resource Bundles'. Seam is a pretty good and extensible framework. It provides you an option to override the built-in 'ResourceLoader' functionality and provide your custom logic. Below is the code for the Java class, which extends the Seam's 'ResourceLoader' component and loads i18n messages from the database:

This component is instantiated, only if the user is authenticated, as the annotations show that it depends on the 'Identity' component. Apart from this, in the overridden methods, I'm getting the 'User' component (which holds the logged-in user details, from database) and loading messages from database (for whatever his/her settings are).

Autoboxing In Java & Bug Patterns

Consider the following example:

1) Some Java Bean:

public class SomeBean implements Serializable {
private int someInt;

public int getSomeInt() {
return this.someInt;

public void setSomeInt(int someInt) {
this.someInt = someInt;

2) And somewhere in some class (with business logic), you have this:

HashMap<String, Integer> someMap = new HashMap<String, Integer>();

...and somewhere down the line, you find a code statement like this:


The above code statement works fine, when there are no 'null' values. But if there is a null value for some key, it fails.....because 'AutoBoxing' throws a NullPointerException when the above code statement tries to unbox a 'null' value.

So, the immediate solution for that would be something like:

Integer someInt = someMap.get("someString");

someBeam.setSomeInt((someInt != null) ? someInt : 0);