Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1888

Log4j throws a java.nio.charset.UnsupportedCharsetException: cp65001

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.8.2
    • Fix Version/s: 2.9.0
    • Component/s: Core
    • Labels:
      None

      Description

      Running a Java spring boot web application using a "java -jar" type of command with a pretty vanilla log4j2.xml file in it, I see the following error.

      2017-04-24 11:47:45,338 main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.ConsoleAppender, element Console. java.nio.charset.UnsupportedCharsetException: cp65001
              at java.nio.charset.Charset.forName(Charset.java:531)
              at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:146)
              at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:134)
              at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:85)
              at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:71)
              at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:218)
              at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:185)
              at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
      

      I am running the "run" command on Windows 10 64x inside a ConEmu console. If I switch to Babun, then I don't see the error.

      This may not exactly be a "bug", but it would be great to not crash the app and fallback to a more accepting encoding perhaps.

        Activity

        Hide
        garydgregory Gary Gregory added a comment -

        Can you post your config file please?

        Show
        garydgregory Gary Gregory added a comment - Can you post your config file please?
        Hide
        md_5 md_5 added a comment -

        Can confirm,

        <?xml version="1.0" encoding="UTF-8"?>
        <Configuration status="WARN" packages="com.mojang.util">
            <Appenders>
                <Console name="WINDOWS_COMPAT" target="SYSTEM_OUT"></Console>
                <Queue name="TerminalConsole">
                    <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
                </Queue>
                <RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
                    <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
                    <Policies>
                        <TimeBasedTriggeringPolicy />
                        <OnStartupTriggeringPolicy />
                    </Policies>
                    <DefaultRolloverStrategy max="1000"/>
                </RollingRandomAccessFile>
            </Appenders>
            <Loggers>
                <Root level="info">
                    <filters>
                        <MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" />
                    </filters>
                    <AppenderRef ref="WINDOWS_COMPAT"/>
                    <AppenderRef ref="File"/>
                    <AppenderRef ref="TerminalConsole"/>
                </Root>
            </Loggers>
        </Configuration>
        

        Happens when users use 'chcp 65001' to attempt a UTF-8 console in cmd.exe on Windows.
        I'm not sure what magic Java does when getting the output charset, but it uses Windows-1252 for System.out even when the properties are set to cp65001 which is why you don't see the error there.

        Show
        md_5 md_5 added a comment - Can confirm, <?xml version= "1.0" encoding= "UTF-8" ?> <Configuration status= "WARN" packages= "com.mojang.util" > <Appenders> <Console name= "WINDOWS_COMPAT" target= "SYSTEM_OUT" ></Console> <Queue name= "TerminalConsole" > <PatternLayout pattern= "[%d{HH:mm:ss} %level]: %msg%n" /> </Queue> <RollingRandomAccessFile name= "File" fileName= "logs/latest.log" filePattern= "logs/%d{yyyy-MM-dd}-%i.log.gz" > <PatternLayout pattern= "[%d{HH:mm:ss}] [%t/%level]: %msg%n" /> <Policies> <TimeBasedTriggeringPolicy /> <OnStartupTriggeringPolicy /> </Policies> <DefaultRolloverStrategy max= "1000" /> </RollingRandomAccessFile> </Appenders> <Loggers> <Root level= "info" > <filters> <MarkerFilter marker= "NETWORK_PACKETS" onMatch= "DENY" onMismatch= "NEUTRAL" /> </filters> <AppenderRef ref= "WINDOWS_COMPAT" /> <AppenderRef ref= "File" /> <AppenderRef ref= "TerminalConsole" /> </Root> </Loggers> </Configuration> Happens when users use 'chcp 65001' to attempt a UTF-8 console in cmd.exe on Windows. I'm not sure what magic Java does when getting the output charset, but it uses Windows-1252 for System.out even when the properties are set to cp65001 which is why you don't see the error there.
        Hide
        garydgregory Gary Gregory added a comment -

        I am looking for a community review for my proposal in branch LOG4J-1888

        Show
        garydgregory Gary Gregory added a comment - I am looking for a community review for my proposal in branch LOG4J-1888
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 4ca638067516f6d488e910a9ff8e0f348d1d5d9f in logging-log4j2's branch refs/heads/LOG4J2-1888 from Gary Gregory
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=4ca6380 ]

        LOG4J2-1888 Log4j throws a
        java.nio.charset.UnsupportedCharsetException: cp65001. Fix proposal.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 4ca638067516f6d488e910a9ff8e0f348d1d5d9f in logging-log4j2's branch refs/heads/ LOG4J2-1888 from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=4ca6380 ] LOG4J2-1888 Log4j throws a java.nio.charset.UnsupportedCharsetException: cp65001. Fix proposal.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 56d76f13fcd7377bc89d0c592f3b2136acd45c7c in logging-log4j2's branch refs/heads/master from Gary Gregory
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=56d76f1 ]

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

        Show
        jira-bot ASF subversion and git services added a comment - Commit 56d76f13fcd7377bc89d0c592f3b2136acd45c7c in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=56d76f1 ] LOG4J2-1888 Log4j throws a java.nio.charset.UnsupportedCharsetException: cp65001.
        Hide
        garydgregory Gary Gregory added a comment -

        The changes are in git master. Please verify and close.

        Show
        garydgregory Gary Gregory added a comment - The changes are in git master. Please verify and close.

          People

          • Assignee:
            Unassigned
            Reporter:
            mmoayyed Misagh Moayyed
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development