From b7b9d0b1e5240053a0337eab504b6dc493e9a66f Mon Sep 17 00:00:00 2001 From: "Ray J. Greenwell" Date: Thu, 2 Jan 2014 14:24:11 -0800 Subject: [PATCH] Don't 'throw' on a translation formatting problem. Translations are sometimes done by third parties long after development is done. A runtime exception is not appropriate here. Return what we can and log extensively. This was noticed when "{0 }" was written instead of "{0}". --- src/main/java/com/threerings/util/MessageBundle.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/threerings/util/MessageBundle.java b/src/main/java/com/threerings/util/MessageBundle.java index d98ada5..415edb4 100644 --- a/src/main/java/com/threerings/util/MessageBundle.java +++ b/src/main/java/com/threerings/util/MessageBundle.java @@ -300,7 +300,16 @@ public class MessageBundle } } - return MessageFormat.format(MessageUtil.escape(msg), args); + try { + return MessageFormat.format(MessageUtil.escape(msg), args); + + } catch (IllegalArgumentException iae) { + // The pattern is invalid or the arguments don't match up. Don't 'throw' because of + // a translation error, we need to do our best for the user. But log it well. + log.warning("Translation error: '" + iae.getMessage() + "'", + "bundle", _path, "key", key, "msg", msg, "args", args, iae); + return msg + StringUtil.toString(args); + } } /**