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

Reconfigure breaks DirectWriteRolloverStrategy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8
    • 2.9.0
    • Plugins
    • 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;
      ...
      

      Attachments

        1. DirectWriteRolloverStrategy.patch
          6 kB
          Christian Vent

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: