Skip to content

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

Merged

Conversation

danielmitterdorfer
Copy link
Member

@danielmitterdorfer danielmitterdorfer commented Jan 20, 2017

Elasticsearch 6.0 removes support for lenient
booleans (see #22200). With this commit we
deprecate all usages of non-strict booleans in
Elasticsearch 5.x so users can already spot
improper usages.

Relates #22200
Relates #22696

Elasticsearch 6.0 removes support for lenient
booleans (see elastic#22000). With this commit we
deprecate all usages of non-strict booleans in
Elasticsearch 5.x so users can already spot
improper usages.

Relates elastic#22000
Relates elastic#22696
@danielmitterdorfer
Copy link
Member Author

@nik9000, @dakrone: Related to #22200, this PR adds deprecation warnings in 5.x for all occurrences of lenient booleans. As you've reviewed #22200, could you please also review this one?

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I left some minor comments

@@ -116,6 +119,10 @@ private AutoCreate(String value) {
List<Tuple<String, Boolean>> expressions = new ArrayList<>();
try {
autoCreateIndex = Booleans.parseBooleanExact(value);
if (Booleans.isStrictlyBoolean(value) == false) {
DEPRECATION_LOGGER.deprecated("Expected a boolean for setting [{}] but got [{}]",
Copy link
Member

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 patterns

Copy link
Member Author

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.

lenientNodeBooleanValue(ignoreUnavailableString, defaultSettings.ignoreUnavailable()),
lenientNodeBooleanValue(allowNoIndicesString, defaultSettings.allowNoIndices()),
lenientNodeBooleanValue(ignoreUnavailableString, "ignore_unavailable", defaultSettings.ignoreUnavailable()),
lenientNodeBooleanValue(allowNoIndicesString, "allow_no_indices", defaultSettings.allowNoIndices()),
Copy link
Member

Choose a reason for hiding this comment

The 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 :-/

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Expected a boolean" -> "Expected a boolean [true/false]"

Copy link
Member

Choose a reason for hiding this comment

The 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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about adding [true/false] to the message

} else if (token == Token.VALUE_STRING) {
return Booleans.parseBoolean(textCharacters(), textOffset(), textLength(), false /* irrelevant */);
rawValue = new String(textCharacters(), textOffset(), textLength());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this might need a charset passed into the String constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only specify a Charset when constructing a String from a byte[] but not when constructing from a char[]. The reason is that in Java a char always represents a Unicode scalar value whereas a byte does not (necessarily).

booleanValue = (Boolean) node;
} else if (node instanceof Number) {
interpretedAsLenient = true;
booleanValue = ((Number) node).intValue() != 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So glad we're getting rid of this so someone doesn't think -1 == false when it actually means true...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

booleanValue = ((Number) node).intValue() != 0;
} else {
String value = node.toString();
booleanValue = !(value.equals("false") || value.equals("0") || value.equals("off"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this ! to == false so eyes don't skip over it? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this is missing parsing "no" as false, in which case this would be breaking, perhaps this should use the helpers in Booleans instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see the original behavior had this inconsistency also (not parsing "no" like all the other boolean methods do)... not sure whether we should try to re-add the consistency or keep the broken behavior.

I'm in favor of re-adding the "no" parsing to be consistent as a semi-bugfix, what do you think? (it's going away in 6.0 anyway...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. This is the original behavior and I just moved code around. I have really mixed feelings about fixing it now because it could lead to bugs in client applications that are very hard to find. Despite this I am still slightly in favor of fixing it too because this problem would appear anyway at latest in 6.0. However, I will fix it in a separate commit after merging this PR.

@danielmitterdorfer danielmitterdorfer merged commit 9946abf into elastic:5.x Jan 23, 2017
@danielmitterdorfer danielmitterdorfer removed the request for review from nik9000 January 23, 2017 14:00
danielmitterdorfer added a commit that referenced this pull request Feb 21, 2017
In #22716 we significantly increased the variety of boolean
representations that are created by the BWC script. The script and the
related tests have only been backported to Elasticsearch 5.3 though.
Hence, if we generate an index with a great variety of boolean
representation but `RestoreBackwardsCompatIT#testOldSnapshot()` tests
only one representation it has to fail.

With this commit we regenerate the BWC indices for 5.2.0 and 5.2.1 with
the older version of the script (which is present on the 5.2 branch) and
only generates one representation of boolean fields as expected by the
test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >deprecation v5.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants