You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2020/04/12 07:32:35 UTC
[logging-log4j2] 01/02: Fix erroneous usage of default locale
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 18f6f6356cb8f361ee82b7c5893ad819796450e2
Author: Trejkaz (pen name) <tr...@trypticon.org>
AuthorDate: Sun Mar 15 22:59:18 2020 +1100
Fix erroneous usage of default locale
---
.../log4j/core/appender/rolling/FileSize.java | 2 +-
.../core/appender/rolling/action/FileSizeTest.java | 31 ++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java
index bd5dce8..f95dc8e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java
@@ -61,7 +61,7 @@ public final class FileSize {
if (matcher.matches()) {
try {
// Get double precision value
- final long value = NumberFormat.getNumberInstance(Locale.getDefault()).parse(
+ final long value = NumberFormat.getNumberInstance(Locale.ROOT).parse(
matcher.group(1)).longValue();
// Get units specified
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java
new file mode 100644
index 0000000..7b0ef87
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileSizeTest.java
@@ -0,0 +1,31 @@
+package org.apache.logging.log4j.core.appender.rolling.action;
+
+import org.apache.logging.log4j.core.appender.rolling.FileSize;
+import org.junit.Test;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class FileSizeTest {
+
+ @Test
+ public void testParse() {
+ assertThat(FileSize.parse("5k", 0), is(5L * 1024));
+ }
+
+ @Test
+ public void testParseInEurope() {
+ // Caveat: Breaks the ability for this test to run in parallel with other tests :(
+ Locale previousDefault = Locale.getDefault();
+ try {
+ Locale.setDefault(new Locale("de", "DE"));
+ assertThat(FileSize.parse("1,000", 0), is(1000L));
+ } finally {
+ Locale.setDefault(previousDefault);
+ }
+ }
+}