Skip to content

Commit 1498b7c

Browse files
committed
Fix deprecated setting specializations (#33412)
Deprecating a some setting specializations (e.g., list settings) does not cause deprecation warning headers and deprecation log messages to appear. This is due to a missed check for deprecation. This commit fixes this for all setting specializations, and ensures that this can not be missed again.
1 parent 81014e0 commit 1498b7c

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public T getDefault(Settings settings) {
6969
}
7070

7171
@Override
72-
public String getRaw(Settings settings) {
72+
String innerGetRaw(final Settings settings) {
7373
throw new UnsupportedOperationException("secure settings are not strings");
7474
}
7575

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,19 @@ public void diff(Settings.Builder builder, Settings source, Settings defaultSett
426426
* Returns the raw (string) settings value. If the setting is not present in the given settings object the default value is returned
427427
* instead. This is useful if the value can't be parsed due to an invalid value to access the actual value.
428428
*/
429-
public String getRaw(Settings settings) {
429+
public final String getRaw(final Settings settings) {
430430
checkDeprecation(settings);
431+
return innerGetRaw(settings);
432+
}
433+
434+
/**
435+
* The underlying implementation for {@link #getRaw(Settings)}. Setting specializations can override this as needed to convert the
436+
* actual settings value to raw strings.
437+
*
438+
* @param settings the settings instance
439+
* @return the raw string representation of the setting value
440+
*/
441+
String innerGetRaw(final Settings settings) {
431442
return settings.get(getKey(), defaultValue.apply(settings));
432443
}
433444

@@ -713,7 +724,7 @@ public T get(Settings settings) {
713724
}
714725

715726
@Override
716-
public String getRaw(Settings settings) {
727+
public String innerGetRaw(final Settings settings) {
717728
throw new UnsupportedOperationException("affix settings can't return values" +
718729
" use #getConcreteSetting to obtain a concrete setting");
719730
}
@@ -820,7 +831,7 @@ public boolean isGroupSetting() {
820831
}
821832

822833
@Override
823-
public String getRaw(Settings settings) {
834+
public String innerGetRaw(final Settings settings) {
824835
Settings subSettings = get(settings);
825836
try {
826837
XContentBuilder builder = XContentFactory.jsonBuilder();
@@ -913,7 +924,7 @@ private ListSetting(String key, Function<Settings, List<String>> defaultStringVa
913924
}
914925

915926
@Override
916-
public String getRaw(Settings settings) {
927+
String innerGetRaw(final Settings settings) {
917928
List<String> array = settings.getAsList(getKey(), null);
918929
return array == null ? defaultValue.apply(settings) : arrayToParsableString(array);
919930
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,26 @@ public void testCompositeValidator() {
462462

463463
}
464464

465+
public void testListSettingsDeprecated() {
466+
final Setting<List<String>> deprecatedListSetting =
467+
Setting.listSetting(
468+
"foo.deprecated",
469+
Collections.singletonList("foo.deprecated"),
470+
Function.identity(),
471+
Property.Deprecated,
472+
Property.NodeScope);
473+
final Setting<List<String>> nonDeprecatedListSetting =
474+
Setting.listSetting(
475+
"foo.non_deprecated", Collections.singletonList("foo.non_deprecated"), Function.identity(), Property.NodeScope);
476+
final Settings settings = Settings.builder()
477+
.put("foo.deprecated", "foo.deprecated1,foo.deprecated2")
478+
.put("foo.deprecated", "foo.non_deprecated1,foo.non_deprecated2")
479+
.build();
480+
deprecatedListSetting.get(settings);
481+
nonDeprecatedListSetting.get(settings);
482+
assertSettingDeprecationsAndWarnings(new Setting[]{deprecatedListSetting});
483+
}
484+
465485
public void testListSettings() {
466486
Setting<List<String>> listSetting = Setting.listSetting("foo.bar", Arrays.asList("foo,bar"), (s) -> s.toString(),
467487
Property.Dynamic, Property.NodeScope);

0 commit comments

Comments
 (0)