From 759d54747b779a1cb11f1b9fbfe8166e62dde03d Mon Sep 17 00:00:00 2001 From: Abhishek Koneru Date: Fri, 29 Jun 2012 16:08:04 -0400 Subject: Coverity CATCH_REXCEPTION and UNREAD_FIELD_CASES --- .../netscape/certsrv/base/MessageFormatter.java | 102 ++++++++++----------- 1 file changed, 49 insertions(+), 53 deletions(-) (limited to 'base/common/src/com/netscape/certsrv') diff --git a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java index 40275b516..f573a227e 100644 --- a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java +++ b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java @@ -88,67 +88,63 @@ public class MessageFormatter { String localizedFormat = null; try { - try { - // if you are worried about the efficiency of the - // following line, dont worry. ResourceBundle has - // an internal cache. So resource bundle wont be - // instantiated everytime you call toString(). + // if you are worried about the efficiency of the + // following line, dont worry. ResourceBundle has + // an internal cache. So resource bundle wont be + // instantiated everytime you call toString(). - localizedFormat = ResourceBundle.getBundle( - resourceBundleBaseName, locale).getString(formatString); - } catch (MissingResourceException e) { - return formatString; + localizedFormat = ResourceBundle.getBundle( + resourceBundleBaseName, locale).getString(formatString); + } catch (MissingResourceException e) { + return formatString; - } - Object[] localizedParams = params; - Object[] localeArg = null; - - if (params != null) { - for (int i = 0; i < params.length; ++i) { - if (!(params[i] instanceof String) || - !(params[i] instanceof Date) || - !(params[i] instanceof Number)) { - if (localizedParams == params) { + } + Object[] localizedParams = params; + Object[] localeArg = null; + + if (params != null) { + for (int i = 0; i < params.length; ++i) { + if (!(params[i] instanceof String) || + !(params[i] instanceof Date) || + !(params[i] instanceof Number)) { + if (localizedParams == params) { + + // only done once + // NB if the following variant of cloning code is used + // localizedParams = (Object [])mParams.clone(); + // it causes ArrayStoreException in + // localizedParams[i] = params[i].toString(); + // below + + localizedParams = new Object[params.length]; + System.arraycopy(params, 0, localizedParams, 0, + params.length); + } + try { + Method toStringMethod = params[i].getClass().getMethod( + "toString", toStringSignature); + if (localeArg == null) { // only done once - // NB if the following variant of cloning code is used - // localizedParams = (Object [])mParams.clone(); - // it causes ArrayStoreException in - // localizedParams[i] = params[i].toString(); - // below - - localizedParams = new Object[params.length]; - System.arraycopy(params, 0, localizedParams, 0, - params.length); - } - try { - Method toStringMethod = params[i].getClass().getMethod( - "toString", toStringSignature); - - if (localeArg == null) { - // only done once - localeArg = new Object[] { locale }; - } - localizedParams[i] = toStringMethod.invoke( - params[i], localeArg); - } catch (Exception e) { - // no method for localization, fall back - localizedParams[i] = params[i].toString(); + localeArg = new Object[] { locale }; } + localizedParams[i] = toStringMethod.invoke( + params[i], localeArg); + } catch (Exception e) { + // no method for localization, fall back + localizedParams[i] = params[i].toString(); } } } - try { - // XXX - runtime exception may be raised by the following function - MessageFormat format = new MessageFormat(localizedFormat); - - return format.format(localizedParams); - } catch (IllegalArgumentException e) { - // XXX - for now, we just print the unformatted message - // if the exception is raised - return localizedFormat; - } - } catch (Exception e) { + } + try { + // XXX - runtime exception may be raised by the following function + MessageFormat format = new MessageFormat(localizedFormat); + + return format.format(localizedParams); + } catch (IllegalArgumentException e) { + // XXX - for now, we just print the unformatted message + // if the exception is raised return localizedFormat; } } -- cgit