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.
This commit is contained in:
Jason Tedor 2019-09-30 14:05:24 -04:00
parent fd421bd12d
commit 890951113f
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
3 changed files with 8 additions and 6 deletions

View File

@ -474,7 +474,7 @@ public class Setting<T> 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);
}

View File

@ -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<TimeValue> 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<TimeValue> 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<Boolean> PUBLISH_DIFF_ENABLE_SETTING =
Setting.boolSetting("discovery.zen.publish_diff.enable", true, Property.Dynamic, Property.NodeScope, Property.Deprecated);
public static final Setting<TimeValue> INITIAL_STATE_TIMEOUT_SETTING =

View File

@ -703,7 +703,6 @@ public class SettingTests extends ESTestCase {
Setting.AffixSetting<List<String>> 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));
}