From 5f4c4e82fd15200e511264e275b59b738269d1f4 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 23 Aug 2004 23:21:40 +0000 Subject: [PATCH] Prevent an ArrayStoreException when doing magical number pluralizing if the array of arguments happens to be a String[]. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3094 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/util/MessageBundle.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index bdfd191cd..45f9e70eb 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -1,5 +1,5 @@ // -// $Id: MessageBundle.java,v 1.26 2004/08/23 22:53:39 mdb Exp $ +// $Id: MessageBundle.java,v 1.27 2004/08/23 23:21:40 ray Exp $ package com.threerings.util; @@ -209,12 +209,18 @@ public class MessageBundle if (msg == null) { if (getResourceString(key + ".n", false) != null) { try { - args[0] = new Integer(args[0].toString()); + // args could be a String[], we need to turn it into + // an Object[] + Object[] newargs = new Object[args.length]; + System.arraycopy(args, 1, newargs, 1, args.length - 1); + newargs[0] = new Integer(args[0].toString()); + args = newargs; msg = getResourceString(key + getSuffix(args)); } catch (Exception e) { Log.warning("Failure doing automatic plural handling " + "[bundle=" + _path + ", key=" + key + - ", args=" + StringUtil.toString(args) + "]."); + ", args=" + StringUtil.toString(args) + + ", error=" + e + "]."); } } else { @@ -236,15 +242,14 @@ public class MessageBundle */ protected String getSuffix (Object[] args) { - String suffix = ""; if (args[0] instanceof Integer) { switch (((Integer)args[0]).intValue()) { - case 0: suffix = ".0"; break; - case 1: suffix = ".1"; break; - default: suffix = ".n"; break; + case 0: return ".0"; + case 1: return ".1"; + default: return ".n"; } } - return suffix; + return ""; } /**