Repository: logging-log4j2
Updated Branches:
  refs/heads/master d52ce48f7 -> ac51b5bc4


[LOG4J2-1799]: Error determining the current charset


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/84d816ff
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/84d816ff
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/84d816ff

Branch: refs/heads/master
Commit: 84d816ffbfac090de73ff283307b473850899723
Parents: 7164e8b
Author: Eduard Gizatullin <[email protected]>
Authored: Thu Feb 2 14:16:10 2017 +0300
Committer: Eduard Gizatullin <[email protected]>
Committed: Thu Feb 2 14:16:10 2017 +0300

----------------------------------------------------------------------
 .../logging/log4j/util/PropertiesUtil.java      |  2 +-
 .../logging/log4j/util/PropertiesUtilTest.java  | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/84d816ff/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index 0fbd1c1..16b9ef6 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -143,7 +143,7 @@ public final class PropertiesUtil {
      */
     public Charset getCharsetProperty(final String name, final Charset 
defaultValue) {
         final String prop = getStringProperty(name);
-        return prop == null ? defaultValue : Charset.forName(name);
+        return prop == null ? defaultValue : Charset.forName(prop);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/84d816ff/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java 
b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
index 131e87b..f25162e 100644
--- 
a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
+++ 
b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.logging.log4j.util;
 
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
 import java.util.Map;
 import java.util.Properties;
 
@@ -62,4 +65,21 @@ public class PropertiesUtilTest {
         assertEquals("2", properties.getProperty("2"));
         assertEquals("3", properties.getProperty("3"));
     }
+
+
+    @Test
+    public void testGetCharsetProperty() throws Exception {
+        Properties p = new Properties();
+        p.setProperty("e.1", StandardCharsets.US_ASCII.name());
+        p.setProperty("e.2", "wrong-charset-name");
+        PropertiesUtil pu = new PropertiesUtil(p);
+
+        assertEquals(Charset.defaultCharset(), pu.getCharsetProperty("e.0"));
+        assertEquals(StandardCharsets.US_ASCII, pu.getCharsetProperty("e.1"));
+        try {
+            pu.getCharsetProperty("e.2");
+            fail("No expected UnsupportedCharsetException");
+        } catch (UnsupportedCharsetException ignored) {
+        }
+    }
 }

Reply via email to