From ffb117d15920fedc7e4246dc4c5881bd1ab47eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0mucr?= Date: Thu, 11 Jun 2020 13:06:36 +0200 Subject: [PATCH] ARTEMIS-2801 Fix ByteUtil.getHumanReadableByteCount() giving inconsistent results HumanReadableByteCountTest test is no longer failing under environments with locales defining different number format. The function now returns values according to the Locale.ROOT locale specification. --- .../main/java/org/apache/activemq/artemis/utils/ByteUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java index 84264d3919..21f8093e3b 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java @@ -21,6 +21,7 @@ import java.io.StringWriter; import java.nio.ByteBuffer; import java.nio.ReadOnlyBufferException; import java.util.Arrays; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -449,6 +450,7 @@ public class ByteUtil { i++; } - return String.format("%.1f%sB", bytes / BYTE_MAGNITUDES[i], BYTE_SUFFIXES[i]); + // Set locale to language/country neutral to avoid different behavior for non-US users + return String.format(Locale.ROOT, "%.1f%sB", bytes / BYTE_MAGNITUDES[i], BYTE_SUFFIXES[i]); } }