Properly remove security index recovered state consumer (#112927)

One of the security index state change listeners attempts to remove
itself once it has received the expected event.

However, since the consumer is a lambda, `this` in
`stateChangeListeners.remove(this);` actually refers to the enclosing
class instance (`SecurityIndexManager.this`) which results in a noop and
not an actual removal of the relevant consumer. 

This PR fixes this by converting the lambda to an anonymous class.  

It's technically a bug, but so minor that it doesn't warrant a bug
changelog IMO; so I'm labelling it a non-issue instead.
This commit is contained in:
Nikolaj Volgushev 2024-09-17 12:24:20 +02:00 committed by GitHub
parent ef154612b7
commit cfe8dfa322
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -344,7 +344,9 @@ public class SecurityIndexManager implements ClusterStateListener {
}
public void onStateRecovered(Consumer<State> recoveredStateConsumer) {
BiConsumer<State, State> stateChangeListener = (previousState, nextState) -> {
BiConsumer<State, State> stateChangeListener = new BiConsumer<>() {
@Override
public void accept(State previousState, State nextState) {
boolean stateJustRecovered = previousState == UNRECOVERED_STATE && nextState != UNRECOVERED_STATE;
boolean stateAlreadyRecovered = previousState != UNRECOVERED_STATE;
if (stateJustRecovered) {
@ -352,6 +354,7 @@ public class SecurityIndexManager implements ClusterStateListener {
} else if (stateAlreadyRecovered) {
stateChangeListeners.remove(this);
}
}
};
stateChangeListeners.add(stateChangeListener);
}