Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not reference values for filtered settings #48066

Merged
merged 5 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,13 @@ private T get(Settings settings, boolean validate) {
} catch (ElasticsearchParseException ex) {
throw new IllegalArgumentException(ex.getMessage(), ex);
} catch (NumberFormatException ex) {
throw new IllegalArgumentException("Failed to parse value [" + value + "] for setting [" + getKey() + "]", ex);
String err = "Failed to parse value" + (isFiltered() ? "" : " [" + value + "]") + " for setting [" + getKey() + "]";
throw new IllegalArgumentException(err, ex);
} catch (IllegalArgumentException ex) {
throw ex;
} catch (Exception t) {
throw new IllegalArgumentException("Failed to parse value [" + value + "] for setting [" + getKey() + "]", t);
String err = "Failed to parse value" + (isFiltered() ? "" : " [" + value + "]") + " for setting [" + getKey() + "]";
throw new IllegalArgumentException(err, t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,32 @@ public void testValidator() {
assertTrue(FooBarValidator.invokedWithDependencies);
}

private static final Setting<String> FILTERED_FOO_BAR_SETTING = new Setting<>(
"foo.bar",
"foobar",
Function.identity(),
new FilteredFooBarValidator(),
Property.Filtered);

static class FilteredFooBarValidator implements Setting.Validator<String> {

@Override
public void validate(String value) {
throw new SettingsException("validate always fails");
}
}

public void testValidatorForFilteredSetting() {
final Settings settings = Settings.builder()
.put("foo.bar", "foo.bar value")
.build();
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> FILTERED_FOO_BAR_SETTING.get(settings));
assertThat(e, hasToString(
containsString("Failed to parse value for setting [" + FILTERED_FOO_BAR_SETTING.getKey() + "]")));
assertThat(e.getCause(), instanceOf(SettingsException.class));
assertThat(e.getCause(), hasToString(containsString("validate always fails")));
}

public void testUpdateNotDynamic() {
Setting<Boolean> booleanSetting = Setting.boolSetting("foo.bar", false, Property.NodeScope);
assertFalse(booleanSetting.isGroupSetting());
Expand Down