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

Removed supress warning 'this-escape' for Java Settings classes #16543

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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 @@ -83,6 +83,12 @@ public static <T> Builder<T> create(String name) {
return new Builder<>(name);
}

static <T> void validateValue(String name, T input, Predicate<T> validator) throws IllegalArgumentException {
if (!validator.test(input)) {
throw new IllegalArgumentException(String.format("Failed to validate setting `%s` with value: `%s`", name, input));
}
}

/**
* Specifically used by Coercible subclass to initialize doing validation in a second phase.
* */
Expand All @@ -94,7 +100,6 @@ protected BaseSetting(String name, boolean strict, Predicate<T> validator) {
this.validator = validator;
}

@SuppressWarnings("this-escape")
protected BaseSetting(String name, T defaultValue, boolean strict, Predicate<T> validator) {
Objects.requireNonNull(name);
Objects.requireNonNull(validator);
Expand All @@ -103,7 +108,7 @@ protected BaseSetting(String name, T defaultValue, boolean strict, Predicate<T>
this.strict = strict;
this.validator = validator;
if (strict) {
validate(defaultValue);
validateValue(name, defaultValue, validator);
}
}

Expand All @@ -127,9 +132,7 @@ protected static <T> Predicate<T> noValidator() {
}

public void validate(T input) throws IllegalArgumentException {
if (!validator.test(input)) {
throw new IllegalArgumentException("Failed to validate setting " + this.name + " with value: " + input);
}
validateValue(this.name, input, this.validator);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@

public abstract class Coercible<T> extends BaseSetting<T> {

@SuppressWarnings("this-escape")
public Coercible(String name, T defaultValue, boolean strict, Predicate<T> validator) {
super(name, strict, validator);

if (strict) {
T coercedDefault = coerce(defaultValue);
validate(coercedDefault);
BaseSetting.validateValue(name, coercedDefault, validator);
this.defaultValue = coercedDefault;
} else {
this.defaultValue = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static <T> List<Setting<T>> wrap(BaseSetting<T> canonicalSetting, String depreca

private DeprecatedAlias<T> deprecatedAlias;

@SuppressWarnings("this-escape")
protected SettingWithDeprecatedAlias(BaseSetting<T> canonicalSetting, String deprecatedAliasName) {
super(canonicalSetting);

Expand Down