harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject [classlib] Looking up exception messages
Date Thu, 08 Oct 2009 11:47:03 GMT
Part of the patch for HARMONY-6346 includes some improvements to the way
we handle localized exception messages.  That prompted me to write down
a few thoughts...

I don't really like the way we do I18N of exception messages.  We create
message string like this

  throw new IOException(Messages.getString("archive.1E"));

The string "archive.1E" is a key into the resource files loaded by the
Messages class based on the current locale.

1) I have no concrete proof, but I'm prepared to bet that 90% of the
exceptions thrown never get asked for their message string.  Yet we are
setting it eagerly - mainly because there is no mechanism on exceptions
to answer the message lazily.

Simple messages may not be too bad, but we also have formatted messages
where we replace token in the message with actual parameters.  A
particular bad example requires formatting more argument strings, e.g.

  throw new IllegalArgumentException(
      Msg.getString("K031e", new String[] { "query", uri.toString() }));

in this case we format the URI and format the message string, and
probably never use the answer.


2) The use of ResourceBundles for handling the strings seems like
overkill too.

Each time we need a string, we load up the entire set of error messages
for that module into a Properties (i.e. hash table) and hold onto them
forever.

The HARMONY-6346 patch makes the resource file soft referenced so that
may help, but I can't help thinking there is a simpler mechanism for
loading the one or two strings that we need rather than the whole lot +
data structure each time.

Regards,
Tim


Mime
View raw message