Skip to content

NPE in ConfigurationScheduler for a frequently executing cron schedule #2073

Closed

Description

Description

For testing purposes, we create a RollingFileAppender with a cron schedule that executes every second (0/1 0/1 * 1/1 * ? *). We noticed that we get the following NullPointerException in random calls.

The cause is most likely the implementation of the method:
org.apache.logging.log4j.core.config.ConfigurationScheduler#scheduleWithCron(org.apache.logging.log4j.core.util.CronExpression, java.util.Date, java.lang.Runnable)

In the case of a frequently executing schedule, there is sometimes a situation where CronRunnable starts executing before the runnable.setScheduledFuture(cronScheduledFuture) method is called, causing an NPE.

The solution to the problem would be to pass cronScheduledFuture even before the first launch of CronRunnable or to introduce an initial delay mechanism.

Configuration

Version: 2.17.2

Operating system: Ubuntu 22.04.3

JDK: Temurin jdk-11.0.21+9

Logs

[2023-12-06T19:28:05.855Z] java.lang.NullPointerException: null
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.config.ConfigurationScheduler$CronRunnable.toString(ConfigurationScheduler.java:256) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.855Z] 	at java.lang.String.valueOf(String.java:2951) ~[?:?]
[2023-12-06T19:28:05.855Z] 	at java.lang.StringBuilder.append(StringBuilder.java:172) ~[?:?]
[2023-12-06T19:28:05.855Z] 	at java.util.concurrent.Executors$RunnableAdapter.toString(Executors.java:519) ~[?:?]
[2023-12-06T19:28:05.855Z] 	at java.lang.String.valueOf(String.java:2951) ~[?:?]
[2023-12-06T19:28:05.855Z] 	at java.lang.StringBuilder.append(StringBuilder.java:172) ~[?:?]
[2023-12-06T19:28:05.855Z] 	at java.util.concurrent.FutureTask.toString(FutureTask.java:513) ~[?:?]
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.config.ConfigurationScheduler.toString(ConfigurationScheduler.java:272) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.appender.rolling.CronTriggeringPolicy.initialize(CronTriggeringPolicy.java:90) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy.initialize(CompositeTriggeringPolicy.java:54) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.setTriggeringPolicy(RollingFileManager.java:431) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.updateData(RollingFileManager.java:710) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.855Z] 	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:151) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.856Z] 	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:100) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.856Z] 	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:217) ~[log4j-core-2.17.2.jar:2.17.2]
[2023-12-06T19:28:05.856Z] 	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:146) ~[log4j-core-2.17.2.jar:2.17.2]

Reproduction

Endless loop creating RollingFileAppender with cron schedule 0/1 0/1 * 1/1 * ? *

Activity

  1. self-assigned this
    on Apr 23, 2024
  2. moved this from To triage to Ready in Log4j bug trackeron Mar 27, 2025
  3. ramanathan1504 commented on May 29, 2026

    @ramanathan1504
    Contributor

    1) Original report characteristics:

    • RollingFileAppender created repeatedly
    • Cron schedule: 0/1 0/1 * 1/1 * ? * (every second)
    • Random NPE path includes:
      • ConfigurationScheduler$CronRunnable.toString(...)
      • ConfigurationScheduler.toString(...)
      • CronTriggeringPolicy.initialize(...)

    Goal of this run:

    2) Harness Used

    Important harness behavior:

    3) Inputs

    • Stress inputs:
      • iterationsPerWorker=300
      • workers=4
      • total planned attempts per run: 1200

    Compared Log4j versions (runtime classpath selection):

    • org.apache.logging.log4j:log4j-core:2.17.2
    • org.apache.logging.log4j:log4j-api:2.17.2
    • org.apache.logging.log4j:log4j-core:2.26.0
    • org.apache.logging.log4j:log4j-api:2.26.0

    4) Raw Outputs

    5.1 Log4j 2.17.2 (/tmp/issue2073-2.17.2.out)

    issue=2073
    log4jVersion=2.17.2
    schedule=0/1 0/1 * 1/1 * ? *
    workers=4
    iterationsPerWorker=300
    attempts=1200
    successfulBuilds=1200
    durationMs=25376
    logDir=/Users/ramanathan/apache/log4j2-workout/logs/issue-2073-standalone
    status=not-reproduced
    

    5.2 Log4j 2.26.0 (/tmp/issue2073-2.26.0.out)

    issue=2073
    log4jVersion=2.26.0
    schedule=0/1 0/1 * 1/1 * ? *
    workers=4
    iterationsPerWorker=300
    attempts=1200
    successfulBuilds=1200
    durationMs=33524
    logDir=/Users/ramanathan/apache/log4j2-workout/logs/issue-2073-standalone
    status=not-reproduced
    

    5.3 Exception Scan Result

    • grep found no NullPointerException and no Exception strings in either output file.

    6) Result Summary

    Metric 2.17.2 2.26.0
    Attempts 1200 1200
    Successful builds 1200 1200
    Failures 0 0
    Status not-reproduced not-reproduced
    Duration (ms) 25376 33524

    6) Notes and Limits

    • This run used macOS + JBR 17 in the current workspace.
    • Original incident mentions Ubuntu 22.04 + Temurin 11.
    • The run is high-frequency and concurrent, but bounded (300 x 4) rather than an infinite loop.
    • Since the issue is random by nature, non-reproduction in one window does not prove impossibility.

    If needed, mirror original environment exactly (Ubuntu 22.04 + Temurin 11) and repeat the same matrix.

  4. added this to the 2.26.2 milestone on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions