Current global config is a volatile variable, hence it must be
acquired into a local variable for proper nullness checks --
otherwise it is open to TOCTOU race conditions leading to NPEs.
Change-Id: I9316b3ed976575726da7a065668c507e15fe0ddf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
private static class GlobalConfig implements DataTreeChangeListener<Global> {
}
private static class GlobalConfig implements DataTreeChangeListener<Global> {
private volatile Global current = null;
@Override
private volatile Global current = null;
@Override
}
boolean allowedUnknownKeys() {
}
boolean allowedUnknownKeys() {
- if (current == null) {
- return false;
- }
+ final Global local = current;
// Deal with null values.
// Deal with null values.
- return Boolean.TRUE.equals(current.isAcceptAllSshKeys());
+ return local != null && Boolean.TRUE.equals(local.isAcceptAllSshKeys());
}
Credentials getCredentials() {
}
Credentials getCredentials() {
- return current != null ? current.getCredentials() : null;
+ final Global local = current;
+ return local != null ? local.getCredentials() : null;