-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Deprecate lenient booleans #22716
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
Deprecate lenient booleans #22716
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,8 +195,8 @@ public static IndicesOptions fromParameters(Object wildcardsString, Object ignor | |
|
||
//note that allowAliasesToMultipleIndices is not exposed, always true (only for internal use) | ||
return fromOptions( | ||
lenientNodeBooleanValue(ignoreUnavailableString, defaultSettings.ignoreUnavailable()), | ||
lenientNodeBooleanValue(allowNoIndicesString, defaultSettings.allowNoIndices()), | ||
lenientNodeBooleanValue(ignoreUnavailableString, "ignore_unavailable", defaultSettings.ignoreUnavailable()), | ||
lenientNodeBooleanValue(allowNoIndicesString, "allow_no_indices", defaultSettings.allowNoIndices()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wish these were static vars instead of hardcoded strings since they're scattered all over this file and the potential for typos is high, but it's not really in the scope of this PR :-/ |
||
expandWildcardsOpen, | ||
expandWildcardsClosed, | ||
defaultSettings.allowAliasesToMultipleIndices(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ | |
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.EnumSet; | ||
import java.util.HashMap; | ||
import java.util.IdentityHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -668,15 +667,25 @@ public static Setting<Integer> intSetting(String key, int defaultValue, Property | |
} | ||
|
||
public static Setting<Boolean> boolSetting(String key, boolean defaultValue, Property... properties) { | ||
return new Setting<>(key, (s) -> Boolean.toString(defaultValue), Booleans::parseBooleanExact, properties); | ||
return new Setting<>(key, (s) -> Boolean.toString(defaultValue), (value) -> parseBoolean(key, value), properties); | ||
} | ||
|
||
public static Setting<Boolean> boolSetting(String key, Setting<Boolean> fallbackSetting, Property... properties) { | ||
return new Setting<>(key, fallbackSetting, Booleans::parseBooleanExact, properties); | ||
return new Setting<>(key, fallbackSetting, (value) -> parseBoolean(key, value), properties); | ||
} | ||
|
||
public static Setting<Boolean> boolSetting(String key, Function<Settings, String> defaultValueFn, Property... properties) { | ||
return new Setting<>(key, defaultValueFn, Booleans::parseBooleanExact, properties); | ||
return new Setting<>(key, defaultValueFn, (value) -> parseBoolean(key, value), properties); | ||
} | ||
|
||
private static Boolean parseBoolean(String key, String value) { | ||
// let the parser handle all cases for non-proper booleans without a deprecation warning by throwing IAE | ||
boolean booleanValue = Booleans.parseBooleanExact(value); | ||
if (Booleans.isStrictlyBoolean(value) == false) { | ||
DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(Setting.class)); | ||
deprecationLogger.deprecated("Expected a boolean for setting [{}] but got [{}]", key, value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Expected a boolean" -> "Expected a boolean [true/false]" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this is all over the place, so if you don't want to add it, that's okay with me. It's up to you :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your suggestion is more user-friendly, so I'll change it in all places. |
||
} | ||
return booleanValue; | ||
} | ||
|
||
public static Setting<ByteSizeValue> byteSizeSetting(String key, ByteSizeValue value, Property... properties) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
import org.elasticsearch.common.io.Streams; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.common.logging.Loggers; | ||
import org.elasticsearch.common.settings.loader.SettingsLoader; | ||
import org.elasticsearch.common.settings.loader.SettingsLoaderFactory; | ||
import org.elasticsearch.common.unit.ByteSizeUnit; | ||
|
@@ -74,7 +76,6 @@ | |
* An immutable settings implementation. | ||
*/ | ||
public final class Settings implements ToXContent { | ||
|
||
public static final Settings EMPTY = new Builder().build(); | ||
private static final Pattern ARRAY_PATTERN = Pattern.compile("(.*)\\.\\d+$"); | ||
|
||
|
@@ -310,7 +311,13 @@ public Long getAsLong(String setting, Long defaultValue) { | |
* returns the default value provided. | ||
*/ | ||
public Boolean getAsBoolean(String setting, Boolean defaultValue) { | ||
return Booleans.parseBoolean(get(setting), defaultValue); | ||
String rawValue = get(setting); | ||
Boolean booleanValue = Booleans.parseBooleanExact(rawValue, defaultValue); | ||
if (rawValue != null && Booleans.isStrictlyBoolean(rawValue) == false) { | ||
DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(Settings.class)); | ||
deprecationLogger.deprecated("Expected a boolean for setting [{}] but got [{}]", setting, rawValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here about adding |
||
} | ||
return booleanValue; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one should be
Expected a boolean [true/false] or index name pattern for setting [{}] but got [{}]
since it technically takes more than just a boolean. Otherwise anyone reading the deprecation log could think it doesn't support index name patternsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll change the wording.