Skip to content

Commit faf6ef8

Browse files
authored
Fixed inconsistent Setting.exist() (#46603)
* Fixed inconsistent Setting.exist Setting.exist will no longer return true if there's setting in keystore with the same name. Also removed synchronization on keySet to lower congestion, possibly constructing keySet multiple times, which should be cheap though. Closes #41830 * Added parameter description * Reuse current methods similar to check in innerGetRaw * Revert formatting changes * Changed ! to ==false
1 parent 88367ae commit faf6ef8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

server/src/main/java/org/elasticsearch/common/settings/Setting.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ public T getDefault(Settings settings) {
404404
* @return true if the setting is present in the given settings instance, otherwise false
405405
*/
406406
public boolean exists(final Settings settings) {
407-
return settings.keySet().contains(getKey());
407+
SecureSettings secureSettings = settings.getSecureSettings();
408+
return settings.keySet().contains(getKey()) &&
409+
(secureSettings == null || secureSettings.getSettingNames().contains(getKey()) == false);
408410
}
409411

410412
/**

server/src/test/java/org/elasticsearch/common/settings/SettingTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,13 @@ public void testExists() {
910910
assertTrue(fooSetting.exists(Settings.builder().put("foo", "bar").build()));
911911
}
912912

913+
public void testExistsWithSecure() {
914+
final MockSecureSettings secureSettings = new MockSecureSettings();
915+
secureSettings.setString("foo", "foo");
916+
Setting<String> fooSetting = Setting.simpleString("foo", Property.NodeScope);
917+
assertFalse(fooSetting.exists(Settings.builder().setSecureSettings(secureSettings).build()));
918+
}
919+
913920
public void testExistsWithFallback() {
914921
final int count = randomIntBetween(1, 16);
915922
Setting<String> current = Setting.simpleString("fallback0", Property.NodeScope);

0 commit comments

Comments
 (0)