Skip to content

Add Boolean#parseBoolean to forbidden-apis #129684

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

kvanerum
Copy link

@kvanerum kvanerum commented Jun 19, 2025

Resolves #59190

Added Boolean#parseBoolean to the list of forbidden-apis.
Resolved the violations against this in tests.
Marked other usages to review in #128993.

@kvanerum kvanerum requested review from a team as code owners June 19, 2025 05:29
Copy link

cla-checker-service bot commented Jun 19, 2025

💚 CLA has been signed

@elasticsearchmachine elasticsearchmachine added v9.1.0 needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team labels Jun 19, 2025
@breskeby breskeby requested a review from mosche June 19, 2025 09:28
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 so much for your contribution @kvanerum, this is very much appreciated! I have a couple of small comments.
Could I also ask you to sign the Contributor Agreement, pls?

@mosche mosche self-assigned this Jun 24, 2025
@mosche mosche added >non-issue :Core/Infra/Core Core issues without another label and removed needs:triage Requires assignment of a team area label labels Jun 24, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Jun 24, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@kvanerum
Copy link
Author

@mosche Thanks for your comments — I’ve reviewed them and added Boolean.valueOf(String s) to the forbidden APIs list.

@mosche
Copy link
Contributor

mosche commented Jun 27, 2025

@elasticmachine test this please

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.

@kvanerum thanks for addressing my comments. This is looking really good, though I have just a few more ... I also triggered tests, let's see where we're at.

@@ -96,6 +97,9 @@ public Set<ScriptContext<?>> getSupportedContexts() {
return Set.of(TemplateScript.CONTEXT, TemplateScript.INGEST_CONTEXT);
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

please also extract a small helper here to minimize the scope of @SuppressForbidden

@@ -246,7 +247,7 @@ public IndexService(
mapperMetrics
);
this.indexFieldData = new IndexFieldDataService(indexSettings, indicesFieldDataCache, circuitBreakerService);
boolean sourceOnly = Boolean.parseBoolean(indexSettings.getSettings().get("index.source_only"));
boolean sourceOnly = isSourceOnly(indexSettings);
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a closer look at this, this can actually be

Suggested change
boolean sourceOnly = isSourceOnly(indexSettings);
boolean sourceOnly = indexSettings.getAsBoolean("index.source_only", false);

Comment on lines 313 to 319
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static boolean isSourceOnly(IndexSettings indexSettings) {
return Boolean.parseBoolean(indexSettings.getSettings().get("index.source_only"));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static boolean isSourceOnly(IndexSettings indexSettings) {
return Boolean.parseBoolean(indexSettings.getSettings().get("index.source_only"));
}

@@ -391,6 +392,9 @@ ScriptScope compile(Compiler compiler, Loader loader, String scriptName, String
}
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

please also extract a small helper here to minimize the scope of @SuppressForbidden

@@ -629,7 +630,7 @@ private static void enrichIndexAbstraction(
if (ia.isSystem()) {
attributes.add(Attribute.SYSTEM);
}
final boolean isFrozen = Boolean.parseBoolean(writeIndex.getSettings().get("index.frozen"));
final boolean isFrozen = isFrozen(writeIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a closer look at this, this can actually be

Suggested change
final boolean isFrozen = isFrozen(writeIndex);
final boolean isFrozen = writeIndex.getSettings().getAsBoolean("index.frozen", false);

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static boolean preferIPv6Addresses() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static boolean preferIPv6Addresses() {
private static boolean preferIPv6Addresses() {

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static boolean getOptimizedMergeEnabledDefault() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static boolean getOptimizedMergeEnabledDefault() {
private static boolean getOptimizedMergeEnabledDefault() {

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static boolean getErrorTraceHeader(ThreadPool threadPool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static boolean getErrorTraceHeader(ThreadPool threadPool) {
private static boolean getErrorTraceHeader(ThreadPool threadPool) {

@@ -45,6 +46,7 @@ public String toString() {
return name().toLowerCase(Locale.ROOT);
}

@SuppressForbidden(reason = "accept lenient boolean field values")
Copy link
Contributor

Choose a reason for hiding this comment

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

please also extract a small helper here to minimize the scope of @SuppressForbidden

@@ -310,6 +311,9 @@ private static <T> T failConversion(Object value, EsType columnType, String type
throw e != null ? new SQLException(message, e) : new SQLException(message);
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
reason = "allow lenient conversion to boolean"

@mosche
Copy link
Contributor

mosche commented Jun 27, 2025

@elasticmachine test this please

@mosche
Copy link
Contributor

mosche commented Jun 27, 2025

@elasticmachine test this please

Comment on lines 379 to 381
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY)));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
Copy link
Contributor

Choose a reason for hiding this comment

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

looking at test failures, these need to default to false

Suggested change
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY)));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE)));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY), false));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE), false));
assertFalse(Booleans.parseBoolean(settingsResponse.getSetting(destIndex, IndexMetadata.SETTING_BLOCKS_WRITE), false));

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 external-contributor Pull request authored by a developer outside the Elasticsearch team >non-issue Team:Core/Infra Meta label for core/infra team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Boolean#parseBoolean to forbidden-apis
3 participants