LOG4J2-2073: Fix NPE in ConfigurationScheduler when scheduling cron tasks
Problem ConfigurationScheduler.scheduleWithCron created a CronRunnable, scheduled it, and only afterwards assigned its CronScheduledFuture. Under fast-firing cron expressions the runnable could execute before its future was set, causing a NullPointerException when calling scheduledFuture.getFireTime().
Root cause Race condition between scheduling the task and assigning the CronScheduledFuture to the runnable.
Fix
Assign a placeholder CronScheduledFuture to the runnable before scheduling.
Update that placeholder with the real ScheduledFuture immediately after scheduling.
Add null-guards in CronRunnable.run() and handle first execution safely.
Enhance toString() to tolerate an unassigned future.
Tests Added CronSchedulerNpeTest which schedules a cron expression firing every second and asserts that it runs without throwing. Before the fix it reproduced the NPE; after the fix all tests pass.
Risks Minimal. Changes are contained to cron scheduling logic and do not alter normal scheduling semantics.