From 890951113f527dec9b38c47c2ccb2cbada41970b Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 30 Sep 2019 14:05:24 -0400 Subject: [PATCH] Make Setting#getRaw have private access (#47287) The method Setting#getRaw leaks implementation details about settings, namely that they are backed by strings. We do not want code to rely upon this, so this commit makes Setting#getRaw private as a first step towards hiding the implementaton details of settings from the rest of the codebase. --- .../org/elasticsearch/common/settings/Setting.java | 2 +- .../elasticsearch/discovery/DiscoverySettings.java | 11 +++++++---- .../elasticsearch/common/settings/SettingTests.java | 1 - 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/settings/Setting.java b/server/src/main/java/org/elasticsearch/common/settings/Setting.java index 396492d8f8f..d4f5751e910 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/Setting.java +++ b/server/src/main/java/org/elasticsearch/common/settings/Setting.java @@ -474,7 +474,7 @@ public class Setting implements ToXContentObject { * Returns the raw (string) settings value. If the setting is not present in the given settings object the default value is returned * instead. This is useful if the value can't be parsed due to an invalid value to access the actual value. */ - public final String getRaw(final Settings settings) { + private String getRaw(final Settings settings) { checkDeprecation(settings); return innerGetRaw(settings); } diff --git a/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java b/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java index e1a0c20864e..c4f8bf02195 100644 --- a/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java +++ b/server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java @@ -42,10 +42,13 @@ public class DiscoverySettings { * sets the timeout for receiving enough acks for a specific cluster state and committing it. failing * to receive responses within this window will cause the cluster state change to be rejected. */ - public static final Setting COMMIT_TIMEOUT_SETTING = - new Setting<>("discovery.zen.commit_timeout", PUBLISH_TIMEOUT_SETTING::getRaw, - (s) -> TimeValue.parseTimeValue(s, TimeValue.timeValueSeconds(30), "discovery.zen.commit_timeout"), - Property.Dynamic, Property.NodeScope, Property.Deprecated); + public static final Setting COMMIT_TIMEOUT_SETTING = new Setting<>( + "discovery.zen.commit_timeout", + PUBLISH_TIMEOUT_SETTING, + (s) -> TimeValue.parseTimeValue(s, TimeValue.timeValueSeconds(30), "discovery.zen.commit_timeout"), + Property.Deprecated, + Property.Dynamic, + Property.NodeScope); public static final Setting PUBLISH_DIFF_ENABLE_SETTING = Setting.boolSetting("discovery.zen.publish_diff.enable", true, Property.Dynamic, Property.NodeScope, Property.Deprecated); public static final Setting INITIAL_STATE_TIMEOUT_SETTING = diff --git a/server/src/test/java/org/elasticsearch/common/settings/SettingTests.java b/server/src/test/java/org/elasticsearch/common/settings/SettingTests.java index b2f73db90f7..0a818b7f2b8 100644 --- a/server/src/test/java/org/elasticsearch/common/settings/SettingTests.java +++ b/server/src/test/java/org/elasticsearch/common/settings/SettingTests.java @@ -703,7 +703,6 @@ public class SettingTests extends ESTestCase { Setting.AffixSetting> listAffixSetting = Setting.affixKeySetting("foo.", "bar", (key) -> Setting.listSetting(key, Collections.singletonList("testelement"), Function.identity(), Property.NodeScope)); expectThrows(UnsupportedOperationException.class, () -> listAffixSetting.get(Settings.EMPTY)); - expectThrows(UnsupportedOperationException.class, () -> listAffixSetting.getRaw(Settings.EMPTY)); assertEquals(Collections.singletonList("testelement"), listAffixSetting.getDefault(Settings.EMPTY)); assertEquals("[\"testelement\"]", listAffixSetting.getDefaultRaw(Settings.EMPTY)); }