1
0
Эх сурвалжийг харах

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
Przemko Robakowski 6 жил өмнө
parent
commit
faf6ef80be

+ 3 - 1
server/src/main/java/org/elasticsearch/common/settings/Setting.java

@@ -404,7 +404,9 @@ public class Setting<T> implements ToXContentObject {
      * @return true if the setting is present in the given settings instance, otherwise false
      */
     public boolean exists(final Settings settings) {
-        return settings.keySet().contains(getKey());
+        SecureSettings secureSettings = settings.getSecureSettings();
+        return settings.keySet().contains(getKey()) &&
+            (secureSettings == null || secureSettings.getSettingNames().contains(getKey()) == false);
     }
 
     /**

+ 7 - 0
server/src/test/java/org/elasticsearch/common/settings/SettingTests.java

@@ -910,6 +910,13 @@ public class SettingTests extends ESTestCase {
         assertTrue(fooSetting.exists(Settings.builder().put("foo", "bar").build()));
     }
 
+    public void testExistsWithSecure() {
+        final MockSecureSettings secureSettings = new MockSecureSettings();
+        secureSettings.setString("foo", "foo");
+        Setting<String> fooSetting = Setting.simpleString("foo", Property.NodeScope);
+        assertFalse(fooSetting.exists(Settings.builder().setSecureSettings(secureSettings).build()));
+    }
+
     public void testExistsWithFallback() {
         final int count = randomIntBetween(1, 16);
         Setting<String> current = Setting.simpleString("fallback0", Property.NodeScope);