From ea69b8e57d2aeeebebdb2c3ccb9f3696d52657bc Mon Sep 17 00:00:00 2001 From: Max Weber Date: Thu, 10 Oct 2019 04:25:53 -0600 Subject: [PATCH] StackFormatter: synchronize access to NumberFormats DecimalFormat likes to copy data into itself when formatting because it is poorly designed, as such it cannot be used by multiple threads at once. --- .../java/net/runelite/client/util/StackFormatter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java index 8a71754620..75d4a9c63f 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java +++ b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java @@ -67,7 +67,7 @@ public class StackFormatter * @param quantity The quantity to convert. * @return a 6 or less character string, possibly with a decimal point, commas or K/M/B suffix */ - public static String quantityToStackSize(long quantity) + public static synchronized String quantityToStackSize(long quantity) { if (quantity < 0) { @@ -127,7 +127,7 @@ public class StackFormatter * @param precise If true, allow thousandths precision if {@code quantity} is larger than 1 million. * Otherwise have at most a single decimal */ - public static String quantityToRSDecimalStack(int quantity, boolean precise) + public static synchronized String quantityToRSDecimalStack(int quantity, boolean precise) { String quantityStr = String.valueOf(quantity); if (quantityStr.length() <= 4) @@ -152,7 +152,7 @@ public class StackFormatter * @param string The string to convert. * @return A long representation of it. */ - public static long stackSizeToQuantity(String string) throws ParseException + public static synchronized long stackSizeToQuantity(String string) throws ParseException { int multiplier = getMultiplier(string); float parsedValue = NUMBER_FORMATTER.parse(string).floatValue(); @@ -164,7 +164,7 @@ public class StackFormatter * * example: {@code 10,123,351}, {@code 5} */ - public static String formatNumber(final long number) + public static synchronized String formatNumber(final long number) { return NUMBER_FORMATTER.format(number); } @@ -176,7 +176,7 @@ public class StackFormatter * * example: {@code 10,123,351}, {@code 5.612} */ - public static String formatNumber(double number) + public static synchronized String formatNumber(double number) { return NUMBER_FORMATTER.format(number); }