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
This commit is contained in:
@@ -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;
|
package com.threerings.util;
|
||||||
|
|
||||||
@@ -209,12 +209,18 @@ public class MessageBundle
|
|||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
if (getResourceString(key + ".n", false) != null) {
|
if (getResourceString(key + ".n", false) != null) {
|
||||||
try {
|
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));
|
msg = getResourceString(key + getSuffix(args));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning("Failure doing automatic plural handling " +
|
Log.warning("Failure doing automatic plural handling " +
|
||||||
"[bundle=" + _path + ", key=" + key +
|
"[bundle=" + _path + ", key=" + key +
|
||||||
", args=" + StringUtil.toString(args) + "].");
|
", args=" + StringUtil.toString(args) +
|
||||||
|
", error=" + e + "].");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -236,15 +242,14 @@ public class MessageBundle
|
|||||||
*/
|
*/
|
||||||
protected String getSuffix (Object[] args)
|
protected String getSuffix (Object[] args)
|
||||||
{
|
{
|
||||||
String suffix = "";
|
|
||||||
if (args[0] instanceof Integer) {
|
if (args[0] instanceof Integer) {
|
||||||
switch (((Integer)args[0]).intValue()) {
|
switch (((Integer)args[0]).intValue()) {
|
||||||
case 0: suffix = ".0"; break;
|
case 0: return ".0";
|
||||||
case 1: suffix = ".1"; break;
|
case 1: return ".1";
|
||||||
default: suffix = ".n"; break;
|
default: return ".n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return suffix;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user