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

NPE in RoutingAppender without pattern

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.13.1
    • Appenders
    • None

    Description

      When I create a RoutingAppender that only has one route and no pattern in the Routes element, I get a NPE as soon as an entry is written into the appender:

      org.apache.logging.log4j.core.appender.AppenderLoggingException: An exception occurred processing Appender Routing	at org.apache.logging.log4j.core.appender.DefaultErrorHandler.error(DefaultErrorHandler.java:93)
      	at org.apache.logging.log4j.core.config.AppenderControl.handleAppenderError(AppenderControl.java:165)
      	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:158)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:508)
      	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:468)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:451)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:426)
      	at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
      	at org.apache.logging.log4j.core.Logger.log(Logger.java:158)
      	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2135)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2089)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2072)
      	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1773)
      	at org.apache.logging.log4j.EventLogger.logEvent(EventLogger.java:47)
      	at org.apache.logging.log4j.core.appender.routing.RoutingAppenderNoPatternTest.routingTest(RoutingAppenderNoPatternTest.java:59)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      	at org.apache.logging.log4j.junit.LoggerContextRule$1.evaluate(LoggerContextRule.java:123)
      	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
      	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
      Caused by: java.lang.NullPointerException
      	at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
      	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getAppender(RoutingAppender.java:300)
      	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getControl(RoutingAppender.java:263)
      	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.append(RoutingAppender.java:242)
      	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
      	... 41 more

      This happens for the following configuration:

      <Routing name="Routing" ignoreExceptions="false">
        <Routes>
          <Route>
            <RollingFile name="Routing-${sd:type}" fileName="${filename}"
                         filePattern="target/routing1/test1-${sd:type}.%i.log.gz"
                         >
              <PatternLayout>
                <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
              </PatternLayout>
              <SizeBasedTriggeringPolicy size="500" />
            </RollingFile>
          </Route>
        </Routes>
      </Routing>
      

       

      Attachments

        Activity

          People

            rgoers Ralph Goers
            christophk Christoph Kaser
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: