Skip to content

Conversation

@mamazzol
Copy link
Contributor

Wrapping user-facing usages of Boolean.parseBoolean in a util method to send a deprecation log.

#128993

@mamazzol mamazzol requested a review from a team as a code owner November 11, 2025 11:23
@mamazzol mamazzol added :Core/Infra/Logging Log management and logging utilities >deprecation labels Nov 11, 2025
@elasticsearchmachine elasticsearchmachine added v9.3.0 Team:Core/Infra Meta label for core/infra team labels Nov 11, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine
Copy link
Collaborator

Hi @mamazzol, I've created a changelog YAML for you. Note that since this PR is labelled >deprecation, you need to update the changelog YAML to fill out the extended information sections.

@elasticsearchmachine
Copy link
Collaborator

Hi @mamazzol, I've updated the changelog YAML for you.

Copy link
Contributor

@mosche mosche left a comment

Choose a reason for hiding this comment

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

Thanks @mamazzol, a couple of points below.
That's a lot less places than I feared to see 😅 And I think some of these could actually be lenient for good.

@SuppressForbidden(reason = "wrap lenient parsing of booleans for deprecation logging.")
public static boolean parseBoolean(String value) {
if ("true".equals(value) == false && "false".equals(value) == false) {
String key = "Boolean#parseBoolean";
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above, this isn't too actionable for customers and would just result in large amount of support cases. I think we have to mention the following parts in the deprecation warning

  • where exactly it happened
  • what the wrong value is
  • what the correct value looks like (true / false)
Comment on lines +19 to +20
+ "This is discouraged in Elasticsearch as it treats all values different than 'true' as false. "
+ "The strict method from Booleans util class should be used instead.";
Copy link
Contributor

@mosche mosche Nov 12, 2025

Choose a reason for hiding this comment

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

I think we need to direct this message more to customers, and more clearly advise them what to use instead. Maybe something like this

Usage of lenient booleans for [{}] [setting | header | system property] such as [{}] was deprecated. Future releases of Elasticsearch may only accept `true` or `false`. 

@SuppressForbidden(reason = "wrap lenient parsing of booleans for deprecation logging.")
public static boolean parseBoolean(String value) {
if ("true".equals(value) == false && "false".equals(value) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Booleans.isBoolean(value) == false?

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
private static boolean getDetectMissingParamsOption(Map<String, String> options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@jdconrad Do you know if options is exposed to users. Could we just switch to strict boolean parsing here?

)
private static boolean parseBoolean(String value) {
return Boolean.parseBoolean(value);
return Booleans.parseBoolean(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

@jdconrad Do you know if params is exposed to users. Could we just switch to strict boolean parsing here?

)
private static boolean useG1GC() {
return Boolean.parseBoolean(JvmInfo.jvmInfo().useG1GC());
return org.elasticsearch.common.util.Booleans.parseBoolean(JvmInfo.jvmInfo().useG1GC());
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on above, we probably should use Booleans.parseBooleanLenient

)
private static boolean preferIPv6Addresses() {
return Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses", "false"));
return Booleans.parseBoolean(System.getProperty("java.net.preferIPv6Addresses", "false"));
Copy link
Contributor

Choose a reason for hiding this comment

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

The JVM does lenient parsing for these, should actually be fine to match that behavior here and switch to parseBooleanLenient

import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.core.SuppressForbidden;

public class Booleans {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming this similar to the "proper" Booleans.parseBoolean might lead to confusion (particularly for reviewers), and potentially we'd end up introducing deprecations in new places for no reason.

i can't think of a great name, though.... maybe LenientBooleans.parseAndCheckForDeprecatedUsage or something in that direction

Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be annotated with UpdateForV10 so we remember to remove the deprecated behavior for the next major.

@elasticsearchmachine
Copy link
Collaborator

Hi @mamazzol, I've updated the changelog YAML for you. Note that since this PR is labelled >deprecation, you need to update the changelog YAML to fill out the extended information sections.

)
private static boolean getErrorTraceHeader(ThreadPool threadPool) {
return Boolean.parseBoolean(threadPool.getThreadContext().getHeaderOrDefault("error_trace", "false"));
return Booleans.parseBoolean(threadPool.getThreadContext().getHeaderOrDefault("error_trace", "false"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Having a closer look, this should already be validated by the rest controller, see in RestRequest and ThreadContext. I think we can switch to strict parsing here.

 @Override public boolean paramAsBoolean(String key, boolean defaultValue) { String rawParam = param(key); // Treat empty string as true because that allows the presence of the url parameter to mean "turn this on" if (rawParam != null && rawParam.length() == 0) { return true; } else { return Booleans.parseBoolean(rawParam, defaultValue); } }
 public void setErrorTraceTransportHeader(RestRequest r) { // set whether data nodes should send back stack trace based on the `error_trace` query parameter if (r.paramAsBoolean("error_trace", RestController.ERROR_TRACE_DEFAULT)) { // We only set it if error_trace is true (defaults to false) to avoid sending useless bytes putHeader("error_trace", "true"); } }
Comment on lines +1 to +11
pr: 137885
summary: Deprecation message for lenient Boolean parsing
area: Infra/Logging
type: deprecation
issues: []
deprecation:
title: Deprecation message for lenient Boolean parsing
area: Infra/Logging
details: Please describe the details of this change for the release notes. You can
use asciidoc.
impact: Please describe the impact of this change to users
Copy link
Contributor

@mosche mosche Nov 12, 2025

Choose a reason for hiding this comment

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

Just a sketch, depending on the final impl ...

Suggested change
pr: 137885
summary: Deprecation message for lenient Boolean parsing
area: Infra/Logging
type: deprecation
issues: []
deprecation:
title: Deprecation message for lenient Boolean parsing
area: Infra/Logging
details: Please describe the details of this change for the release notes. You can
use asciidoc.
impact: Please describe the impact of this change to users
pr: 137885
summary: Add deprecation for usage of lenient booleans for analysis boolean setting (3rd party plugins) and boolean system properties.
area: Infra/Logging
type: deprecation
issues:
- 128993
deprecation:
title: Add deprecation for usage of lenient booleans for analysis boolean setting (3rd party plugins) and boolean system properties.
area: Infra/Logging
details: Usage of lenient booleans was deprecated for analysis boolean setting in external plugins using the stable plugin API and various boolean system properties.
impact: Usage of lenient booleans other than `true` or `false` will result in deprecations logs and corresponding header warnings. Future releases of ES may only accept strict boolean values `true` or `false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Logging Log management and logging utilities >deprecation Team:Core/Infra Meta label for core/infra team v9.3.0

3 participants