Hi all!
I'd like to inform the development team of what it seems a
little bug in i18n resources management, that causes
NullPointerException in errors tag rendering, when DbForms
application are configured without internationalization support
(that is, no "resourceBundle" parameter specified in web.xml).

Walking thru the code i've found that the
org.dbforms.servlets.ConfigServlet initializes i18n
calling the protected method initApplicationResources(),
which has the responsability to call
MessageResources.setSubClass(String) to define the i18n
ResourceBundle class.

The logging messages written by
ConfigServlet ::initApplicationResources()
states that if "resourceBundle" init parameter is not
present, i18n will be disabled, and this is handled
returning without calling MessageResources.setSubClass(String),
leaving msgRes attribute of MessageResources uninitialized.
But that case is not correctly handled by MessageResources class,
where we found the methods:

[snip]
   ....
   /******************************************************************
    *  Retrieve message from ResourceBundle.
    *  If the ResourceBundle is not yet cached, cache it
    *  and retreive message.
    *
    *  @param  <code>String</code> : Message key to lookup.
    *  @param  <code>Locale</code> : Locale object to map message
    *          with good ResourceBundle.
    *
    *  @return <code>String</code> : Message resolve, null if not found.
    *******************************************************************/
   public static String getMessage(String msg, Locale loc)
   {
      return msgRes.getMessage(msg, loc);
   }

   /******************************************************************
    * Retrieve message from ResourceBundle and replace parameter "{x}"
    * with values in parms array.
    *
    * @param  <code>String</code> : Message key to lookup.
    * @param  <code>Locale</code> : Locale object to map message with
    *         good ResourceBundle.
    * @param  <code>String[]</code> : Parameters to replace "{x}" in
    *         message .
    *
    * @return <code>String</code> : Message resolve with parameter
    *         replaced, null if message key not found.
    ******************************************************************/
   public static String getMessage(String msg, Locale loc, String[] parms)
   {
      return msgRes.getMessage(msg, loc, parms);
   }
  ....
[snip]

which don't test for msgRes == null before using it, violating
the post-condition documented into code.

If the behaviour of ConfigServlet is correct, then
MessageResources  implementation must be changed  as follow:

[snip]
   ....
   public static String getMessage(String msg, Locale loc)
   {
      return (msgRes == null)?null:msgRes.getMessage(msg, loc);
   }

....

   public static String getMessage(String msg, Locale loc, String[] parms)
   {
      return (msgRes == null)?null:msgRes.getMessage(msg, loc, parms);
   }
  ....
[snip]

If this not apply, then "resourceBundle" init parameter must
be stated mandatory and ConfigServlet implementation must
be changed.


Hope this could help Roberto








------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ DbForms Mailing List

http://www.wap-force.net/dbforms

Reply via email to