Repository: logging-log4j2
Updated Branches:
  refs/heads/master f2ddaf93a -> 56d76f13f


[LOG4J2-1888] Log4j throws a
java.nio.charset.UnsupportedCharsetException: cp65001.

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

Branch: refs/heads/master
Commit: 56d76f13fcd7377bc89d0c592f3b2136acd45c7c
Parents: f2ddaf9
Author: Gary Gregory <[email protected]>
Authored: Tue Aug 15 17:44:46 2017 -0600
Committer: Gary Gregory <[email protected]>
Committed: Tue Aug 15 17:44:46 2017 -0600

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/util/PropertiesUtil.java   | 8 +++++++-
 .../org/apache/logging/log4j/util/PropertiesUtilTest.java    | 6 +-----
 .../apache/logging/log4j/core/appender/ConsoleAppender.java  | 8 ++++----
 src/changes/changes.xml                                      | 3 +++
 4 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/56d76f13/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 76805ca..66270a5 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
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -167,7 +168,12 @@ public final class PropertiesUtil {
      */
     public Charset getCharsetProperty(final String name, final Charset 
defaultValue) {
         final String prop = getStringProperty(name);
-        return prop == null ? defaultValue : Charset.forName(prop);
+        try {
+            return prop == null ? defaultValue : Charset.forName(prop);
+        } catch (UnsupportedCharsetException e) {
+            LowLevelLogUtil.logException("Unable to get Charset '" + name + 
"', using default " + defaultValue, e);
+            return defaultValue;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/56d76f13/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 7a256e0..99dbeb9 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
@@ -76,10 +76,6 @@ public class PropertiesUtilTest {
 
         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 (final UnsupportedCharsetException ignored) {
-        }
+        assertEquals(Charset.defaultCharset(), pu.getCharsetProperty("e.2"));
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/56d76f13/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
index 6243944..ab34d35 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
@@ -71,7 +71,7 @@ public final class ConsoleAppender extends 
AbstractOutputStreamAppender<OutputSt
         SYSTEM_OUT {
             @Override
             public Charset getDefaultCharset() {
-                return getCharset("sun.stdout.encoding");
+                return getCharset("sun.stdout.encoding", 
Charset.defaultCharset());
             }
         },
         
@@ -79,14 +79,14 @@ public final class ConsoleAppender extends 
AbstractOutputStreamAppender<OutputSt
         SYSTEM_ERR {
             @Override
             public Charset getDefaultCharset() {
-                return getCharset("sun.stderr.encoding");
+                return getCharset("sun.stderr.encoding", 
Charset.defaultCharset());
             }
         };
         
         public abstract Charset getDefaultCharset();
         
-        protected Charset getCharset(final String property) {
-            return new 
PropertiesUtil(PropertiesUtil.getSystemProperties()).getCharsetProperty(property);
+        protected Charset getCharset(final String property, Charset 
defaultCharset) {
+            return new 
PropertiesUtil(PropertiesUtil.getSystemProperties()).getCharsetProperty(property,
 defaultCharset);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/56d76f13/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9ff328a..b753dc7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -55,6 +55,9 @@
       <action issue="LOG4J2-1864" dev="mattsicker" type="add" due-to="Matthias 
Kappeller">
         Support capped collections for MongoDb appender.
       </action>
+      <action issue="LOG4J2-1888" dev="ggregory" type="fix" due-to="Misagh 
Moayyed">
+        Log4j throws a java.nio.charset.UnsupportedCharsetException: cp65001.
+      </action>
       <action issue="LOG4J2-1990" dev="ggregory" type="fix" due-to="Philippe 
Mouawad">
         ConcurrentModificationException logging a parameter of type Map.
       </action>

Reply via email to