Error in AbstractComponent#getLocale() ?


public Locale getLocale() {
        if (locale != null) {
            return locale;
        }
        if (parent != null) {
            return parent.getLocale();
        }
        final Application app = getApplication();
        if (app != null) {
            return app.getLocale();
        }
        return null; 
        // should not this be:
        return Locale.getDefault();
}

I don’t agree. You can’t always assume that the jvm default locale has a sensible value. By returning null instead of the default locale, the application developer can detect the situation and chose whether to use Locale.getDefault() or using some other custom logic for selecting the locale.

Okay clear. Maybe this intention should be documented in the javadoc?

Regards,

Ronald

Now that I looked at the code again, I realized that the JVM default Locale is actually used, but only for Application instances where no other Locale has been defined.

The null case in AbstractComponent.getLocale works as documented: null might be returned if the component is not attached to the component hierarchy of an Application. This can be used to differentiate between not being attached (null is returned) and being attached (a specific Locale or the default Locale is returned).