Log4j 2
  1. Log4j 2
  2. LOG4J2-152

NullPointerException in (...)appender.rolling.helper.FileRenameAction if filePattern does not contain a parent directory

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta3
    • Fix Version/s: 2.0-beta4
    • Component/s: Appenders
    • Labels:
      None

      Description

      ERROR StatusLogger Error in synchronous task java.lang.NullPointerException
      at org.apache.logging.log4j.core.appender.rolling.helper.FileRenameAction.execute(FileRenameAction.java:85)
      at org.apache.logging.log4j.core.appender.rolling.helper.FileRenameAction.execute(FileRenameAction.java:71)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:140)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:97)
      at atlas.infra.log.RollingRandomAccessFileAppender.append(RollingRandomAccessFileAppender.java:52)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:98)
      at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:335)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:316)
      at org.apache.logging.log4j.core.Logger$PrivateConfig.logEvent(Logger.java:304)

      To reproduce, in log4j2.xml, specify a filePattern without a parent directory:
      <appenders>
      <RollingFile name="RollingFile" fileName="logs/app.log"
      filePattern="fileWithoutParentDir-%d

      {MM-dd-yyyy}

      -%i.log.gz">

      To fix, change org.apache.logging.log4j.core.appender.rolling.helper.FileRenameAction#execute(File, File, boolean) (line 85): add null check:

      if (parent != null && !parent.exists()) { // parent is null if not specified in filePattern

        Activity

        Hide
        Remko Popma added a comment -

        The fix works fine. Thanks!

        Show
        Remko Popma added a comment - The fix works fine. Thanks!
        Hide
        Ralph Goers added a comment -

        Fixed in revision 1435044. Please verify and close.

        Show
        Ralph Goers added a comment - Fixed in revision 1435044. Please verify and close.
        Hide
        Remko Popma added a comment -

        The offending line in trunk is line 79:
        Current:
        if (!parent.exists()) {

        Proposed change:
        if (parent != null && !parent.exists()) {

        Show
        Remko Popma added a comment - The offending line in trunk is line 79: Current: if (!parent.exists()) { Proposed change: if (parent != null && !parent.exists()) {
        Hide
        Remko Popma added a comment -

        My mistake. I was using log4j-api-2.0-beta3.jar and log4j-core-2.0-beta3.jar. I marked it wrong in the JIRA ticket. Will edit the ticket to specify the correct version.

        Show
        Remko Popma added a comment - My mistake. I was using log4j-api-2.0-beta3.jar and log4j-core-2.0-beta3.jar. I marked it wrong in the JIRA ticket. Will edit the ticket to specify the correct version.
        Hide
        Gary Gregory added a comment -

        Hi Remko,

        You marked this issue as beta-2, we have beta-3 out now. Can you run against the trunk version? You''ll have to check out the source and build. That would help match up the source with the stack trace more easily. Unless the issue is already fixed in trunk that is.

        Thank you,
        Gary

        Show
        Gary Gregory added a comment - Hi Remko, You marked this issue as beta-2, we have beta-3 out now. Can you run against the trunk version? You''ll have to check out the source and build. That would help match up the source with the stack trace more easily. Unless the issue is already fixed in trunk that is. Thank you, Gary

          People

          • Assignee:
            Ralph Goers
            Reporter:
            Remko Popma
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development