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

Reconfigure breaks DirectWriteRolloverStrategy

    Details

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

      Description

      A reconfigure breaks DirectWriteRolloverStrategy which leads to the errors similar to that one:

      2017-06-30 10:45:56,010 Log4j2-TF-4-Scheduled-3 ERROR Log4j2 ConfigurationScheduler caught error running command java.lang.NullPointerException: activeFileName
      	at java.util.Objects.requireNonNull(Objects.java:228)
      	at org.apache.logging.log4j.core.appender.rolling.RolloverDescriptionImpl.<init>(RolloverDescriptionImpl.java:60)
      	at org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy.rollover(DirectWriteRolloverStrategy.java:220)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:388)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:304)
      	at org.apache.logging.log4j.core.appender.rolling.CronTriggeringPolicy.rollover(CronTriggeringPolicy.java:153)
      	at org.apache.logging.log4j.core.appender.rolling.CronTriggeringPolicy.access$100(CronTriggeringPolicy.java:43)
      	at org.apache.logging.log4j.core.appender.rolling.CronTriggeringPolicy$CronTrigger.run(CronTriggeringPolicy.java:176)
      	at org.apache.logging.log4j.core.config.ConfigurationScheduler$CronRunnable.run(ConfigurationScheduler.java:230)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      

      Durring the rollover the system is using the field currentFileName, which might be null after an reconfigure:

      org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy#rollover
      ...
      Action compressAction = null;
      final String sourceName = currentFileName;
      String compressedName = sourceName;
      ...
      

      Instead of that I'd propose to use getCurrentFileName() directly, to access the field. Doing so the field would be initialised again, if necessary.

      org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy#rollover
      ...
      Action compressAction = null;
      final String sourceName = getCurrentFileName(manager);
      String compressedName = sourceName;
      ...
      

        Issue Links

          Activity

          Hide
          cvent Christian Vent added a comment -

          I added a patch to fix the issue, including a test to rebuild the error

          Show
          cvent Christian Vent added a comment - I added a patch to fix the issue, including a test to rebuild the error
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 5e92ed9fad60b6034676ac74f7ac4f3c072eb315 in logging-log4j2's branch refs/heads/master from Christian Vent
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=5e92ed9 ]

          LOG4J2-1961 Reconfigure breaks DirectWriteRolloverStrategy.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 5e92ed9fad60b6034676ac74f7ac4f3c072eb315 in logging-log4j2's branch refs/heads/master from Christian Vent [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=5e92ed9 ] LOG4J2-1961 Reconfigure breaks DirectWriteRolloverStrategy.
          Hide
          garydgregory Gary Gregory added a comment -

          In Git master now. Please verify and close.

          Show
          garydgregory Gary Gregory added a comment - In Git master now. Please verify and close.
          Hide
          mikaelstaldal Mikael Ståldal added a comment -

          The new test fails on Java 8 and Java 9:

          [ERROR] Failures:
          [ERROR] RollingAppenderDirectWriteWithReconfigureTest.testRollingFileAppenderWithReconfigure:68
          Expected: is <2>
               but: was <1> 
          
          Show
          mikaelstaldal Mikael Ståldal added a comment - The new test fails on Java 8 and Java 9: [ERROR] Failures: [ERROR] RollingAppenderDirectWriteWithReconfigureTest.testRollingFileAppenderWithReconfigure:68 Expected: is <2> but: was <1>
          Hide
          mikaelstaldal Mikael Ståldal added a comment -

          Christian Vent Have you tried this on Java 7 or Java 8?

          If you have tried only on Java 7, would it be possible for you to test it on Java 8 as well?

          Show
          mikaelstaldal Mikael Ståldal added a comment - Christian Vent Have you tried this on Java 7 or Java 8? If you have tried only on Java 7, would it be possible for you to test it on Java 8 as well?
          Hide
          cvent Christian Vent added a comment -

          Mikael Ståldal I'm using Java 8 in my JDK and the test is still woking locally. I removed the assume and run the test several times in my IDE and with mvn.

          Show
          cvent Christian Vent added a comment - Mikael Ståldal I'm using Java 8 in my JDK and the test is still woking locally. I removed the assume and run the test several times in my IDE and with mvn.
          Hide
          mikaelstaldal Mikael Ståldal added a comment -

          Which OS are you using? Can you show the output of "java -version"

          Show
          mikaelstaldal Mikael Ståldal added a comment - Which OS are you using? Can you show the output of "java -version"
          Hide
          cvent Christian Vent added a comment -

          Sure, I'm using MacOS Sierra (10.12.x).

          Java -version
          java version "1.8.0_121"
          Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
          Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
          
          Show
          cvent Christian Vent added a comment - Sure, I'm using MacOS Sierra (10.12.x). Java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

            People

            • Assignee:
              Unassigned
              Reporter:
              cvent Christian Vent
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development