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.

        Issue Links

          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.
          Hide
          steudle.f@duerr.de Frank Steudle added a comment - - edited

          Today I updated my fitnesse project to use the 2.9.0 versions of log4-core and log4j-api. Now I am encountering the above mentioned exception. I am using ISO-8859-1 on my Eclipse computer to store the files. But the execution environment is plain UTF-8. Therefore I am using those parameters to run my fitnesse project:

          • -Dsun.jnu.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS
          • -Dfile.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS
          • chcp 65001: to switch the Windows console encoding to UTF8

          Here is the exception, which is thrown:

          C:\Users\admin\Desktop\RabbitDevInstall\Testtool>java -jar RunRabbitRun-2.0-SNAPSHOT-jar-with-dependencies.jar start ./Resources
          Picked up JAVA_TOOL_OPTIONS: -Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0
          Unable to get Charset 'sun.stdout.encoding', using default UTF-8
          java.nio.charset.UnsupportedCharsetException: cp65001
                  at java.nio.charset.Charset.forName(Unknown Source)
                  at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:172)
                  at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:89)
                  at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:74)
                  at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:222)
                  at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:189)
                  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:958)
                  at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
                  at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
                  at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
                  at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
                  at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
                  at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
                  at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
                  at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
                  at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
                  at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
                  at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
                  at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
                  at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551)
                  at de.duerr.fitnesse.RunRabbitRun.<clinit>(RunRabbitRun.java:24)
          11:37:19.176 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over first parameter: start
          11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over Fitnesse directory: ./Resources
          11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -d
          11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: ./Resources
          11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -r
          11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: FitNesseRoot
          Sep 20, 2017 11:37:19 AM fitnesse.ConfigurationParameter loadProperties
          INFORMATION: No configuration file found (C:\Users\admin\Desktop\RabbitDevInstall\Testtool\Resources\plugins.properties)
          Bootstrapping FitNesse, the fully integrated standalone wiki and acceptance testing framework.
          root page: fitnesse.wiki.fs.WikiFilePage: FitNesseRoot
          logger: none
          authenticator: fitnesse.authentication.PromiscuousAuthenticator
          page factory: fitnesse.html.template.PageFactory
          page theme: bootstrap
          Starting FitNesse on port: 80
          

          However, my project is running well. Seems to work anyway.

          Here is my log4j configuration file:

          <?xml version="1.0" encoding="UTF-8"?>
          <Configuration status="WARN">
            <Appenders>
              <Console name="Console" target="SYSTEM_OUT">
                <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
              </Console>
              
              <RollingFile name="RollingFile" fileName="logs/rrr.log"
                           filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log">
                <PatternLayout>
                  <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
                </PatternLayout>
                <Policies>
                  <TimeBasedTriggeringPolicy />
                  <OnStartupTriggeringPolicy />
                  <SizeBasedTriggeringPolicy size="20 MB"/>
                </Policies>
              </RollingFile>
              
            </Appenders>
            <Loggers>
              <Root level="all">
                <AppenderRef ref="RollingFile"/>
                <AppenderRef ref="Console"/>
              </Root>
            </Loggers>
          </Configuration>
          

          And here is my starting script:

          SET RRR_RESOURCES=.
          
          SET JAVA_TOOL_OPTIONS=-Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0
          
          chcp 65001
          
          java -version
          
          java -XshowSettings
          
          java -jar ${project.artifactId}-${project.version}-jar-with-dependencies.jar start ./Resources
          
          
          Show
          steudle.f@duerr.de Frank Steudle added a comment - - edited Today I updated my fitnesse project to use the 2.9.0 versions of log4-core and log4j-api. Now I am encountering the above mentioned exception. I am using ISO-8859-1 on my Eclipse computer to store the files. But the execution environment is plain UTF-8. Therefore I am using those parameters to run my fitnesse project: -Dsun.jnu.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS chcp 65001: to switch the Windows console encoding to UTF8 Here is the exception, which is thrown: C:\Users\admin\Desktop\RabbitDevInstall\Testtool>java -jar RunRabbitRun-2.0-SNAPSHOT-jar-with-dependencies.jar start ./Resources Picked up JAVA_TOOL_OPTIONS: -Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0 Unable to get Charset 'sun.stdout.encoding', using default UTF-8 java.nio.charset.UnsupportedCharsetException: cp65001 at java.nio.charset.Charset.forName(Unknown Source) at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:172) at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:89) at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:74) at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:222) at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:189) 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:958) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890) at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513) at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237) at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249) at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634) at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551) at de.duerr.fitnesse.RunRabbitRun.<clinit>(RunRabbitRun.java:24) 11:37:19.176 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over first parameter: start 11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over Fitnesse directory: ./Resources 11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -d 11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: ./Resources 11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -r 11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: FitNesseRoot Sep 20, 2017 11:37:19 AM fitnesse.ConfigurationParameter loadProperties INFORMATION: No configuration file found (C:\Users\admin\Desktop\RabbitDevInstall\Testtool\Resources\plugins.properties) Bootstrapping FitNesse, the fully integrated standalone wiki and acceptance testing framework. root page: fitnesse.wiki.fs.WikiFilePage: FitNesseRoot logger: none authenticator: fitnesse.authentication.PromiscuousAuthenticator page factory: fitnesse.html.template.PageFactory page theme: bootstrap Starting FitNesse on port: 80 However, my project is running well. Seems to work anyway. Here is my log4j configuration file: <?xml version= "1.0" encoding= "UTF-8" ?> <Configuration status= "WARN" > <Appenders> <Console name= "Console" target= "SYSTEM_OUT" > <PatternLayout pattern= "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name= "RollingFile" fileName= "logs/rrr.log" filePattern= "logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log" > <PatternLayout> <Pattern> %d %p %c{1.} [%t] %m%n </Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> <OnStartupTriggeringPolicy /> <SizeBasedTriggeringPolicy size= "20 MB" /> </Policies> </RollingFile> </Appenders> <Loggers> <Root level= "all" > <AppenderRef ref= "RollingFile" /> <AppenderRef ref= "Console" /> </Root> </Loggers> </Configuration> And here is my starting script: SET RRR_RESOURCES=. SET JAVA_TOOL_OPTIONS=-Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0 chcp 65001 java -version java -XshowSettings java -jar ${project.artifactId}-${project.version}-jar-with-dependencies.jar start ./Resources
          Hide
          steudle.f@duerr.de Frank Steudle added a comment -

          Found help for my problem in issue https://issues.apache.org/jira/browse/LOG4J2-2053. Thanks!

          Show
          steudle.f@duerr.de Frank Steudle added a comment - Found help for my problem in issue https://issues.apache.org/jira/browse/LOG4J2-2053 . Thanks!

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development