I think this is a Concurrency issues. the _delegate variable in SubtituteLogger could be null in one case. Multiple threads concurrently call LoggerFactory.getILoggerFactory(),Thread A execute fixSubstitutedLoggers,found SUBST_FACTORY.getLoggers() is empty,then finish this method,Before Thread A execute playRecordedEvents mehod, Thread B execute getILoggerFactory,found the INITIALIZATION_STATE is ONGOING_INITIALIZATION,then return the SUBST_FACTORY and call SUBST_FACTORY.getLogger("name").debug("message"),SubstituteLogger.delegate will be call,found _delegate is null,so getEventRecordingLogger will EventRecodingLogger.recordEventWill be executed,the eventList is not empty. Let us return to the thread A , execute playRecordedEvents()found eventsis not empty,then throw NPE when execute substLogger.isDelegateEventAware(),caused by _delegate is null,because the SubstituteLogger.setDelegate method was never executed。
|