OPENDJ-1706 Persistit: online import fails with NPE
Code review: Matthew Swift
Problem happened when disabling the backend before online import.
Before applying the change, the config backend was iterating over the list of listeners for this configuration.
It is important to note that the list was a CopyOnWriteArrayList, and we used its iterator.
When disabling the backend, the first listener is the backend itself. This ends up calling pluggable.BackendImpl.finalizeBackend() which calls RootContainer.close(), EntryContainer.close(), AttributeIndex.close(), etc.
The net effect is that the RootContainer, EntryContainer, and AttributeIndex deregister themselves as change listeners of that config.
In the end, before the first iteration (on the backend), there are 9 config change listeners to notify. After the first loop iteration, there is only one config change listener remaining on the list of listeners: it is actually the backend we just iterated over!
However, remember the loop is performed on the CopyOnWriteArrayList iterator, which was initilized when the list had 9 elements. So it keeps notifying listeners which are no longer interested in the change.
The code then end up trying to update the indexes, by opening a transaction on the database. Problem is that the database has been closed by the call to pluggable.BackendImpl.finalizeBackend() => and BOOM! NullPointerException!
The fix consists in verifying that each listener to be notified is still interested in the config change; i.e. did it deregister itself from listening?
ConfigFileHandler.java:
In addEntry(), replaceEntry(), deleteEntry(), always verify the listener is still interested in the config change before notifying it.