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 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -35,6 +35,7 @@ java.nio.channels.SocketChannel#connect(java.net.SocketAddress)
# org.elasticsearch.core.Booleans#parseBoolean(java.lang.String) directly on the string.
@defaultMessage use org.elasticsearch.core.Booleans#parseBoolean(java.lang.String)
java.lang.Boolean#getBoolean(java.lang.String)
java.lang.Boolean#parseBoolean(java.lang.String)

org.apache.lucene.util.IOUtils @ use @org.elasticsearch.core.internal.io instead

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package org.elasticsearch.core.internal.provider;

import org.elasticsearch.core.SuppressForbidden;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -465,6 +467,9 @@ private static CodeSource codeSource(URL baseURL, String jarName) throws Malform
return new CodeSource(new URL(baseURL, jarName), (CodeSigner[]) null /*signers*/);
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
private static boolean isMultiRelease(ClassLoader parent, String jarPrefix) throws IOException {
try (InputStream is = parent.getResourceAsStream(jarPrefix + "/META-INF/MANIFEST.MF")) {
if (is != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ private static void parseCsv(Path csvPath, MethodDescriptorConsumer methodConsum
}
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public static void main(String[] args) throws IOException {
var csvFilePath = Path.of(args[0]);
boolean bubbleUpFromPublic = args.length >= 2 && Boolean.parseBoolean(args[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.elasticsearch.core.Booleans;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
Expand All @@ -26,8 +27,8 @@ private static ElasticsearchCluster makeCluster() {

// On Serverless, we want to disallow scripted metrics aggs per default.
// The following override allows us to still run the scripted metrics agg tests without breaking bwc.
boolean disableAllowListPerDefault = Boolean.parseBoolean(
System.getProperty("tests.disable_scripted_metric_allow_list_per_default")
boolean disableAllowListPerDefault = Booleans.parseBoolean(
System.getProperty("tests.disable_scripted_metric_allow_list_per_default", "false")
);
if (disableAllowListPerDefault) {
return cluster.setting("search.aggs.only_allowed_metric_scripts", "false").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
Expand Down Expand Up @@ -51,7 +52,7 @@ private static ElasticsearchCluster createCluster() {
if (initTestSeed().nextBoolean()) {
clusterBuilder.setting("xpack.license.self_generated.type", "trial");
}
boolean setNodes = Boolean.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
boolean setNodes = Booleans.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
if (setNodes) {
clusterBuilder.nodes(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
Expand Down Expand Up @@ -50,7 +51,7 @@ private static ElasticsearchCluster createCluster() {
.setting("xpack.security.enabled", "true")
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password");
boolean setNodes = Boolean.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
boolean setNodes = Booleans.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
if (setNodes) {
clusterBuilder.nodes(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
Expand Down Expand Up @@ -48,7 +49,7 @@ private static ElasticsearchCluster createCluster() {
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "true")
.user("x_pack_rest_user", "x-pack-test-password");
boolean setNodes = Boolean.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
boolean setNodes = Booleans.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
if (setNodes) {
clusterBuilder.nodes(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class GeoIpReindexedIT extends ParameterizedFullClusterRestartTestCase {

// e.g. use ./gradlew -Dtests.jvm.argline="-Dgeoip_test_with_security=false" ":modules:ingest-geoip:qa:full-cluster-restart:check"
// to set this to false, if you so desire
private static final boolean useSecurity = Boolean.parseBoolean(System.getProperty("geoip_test_with_security", "true"));
private static final boolean useSecurity = Booleans.parseBoolean(System.getProperty("geoip_test_with_security", "true"));

private static final ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.elasticsearch.SpecialPermission;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.painless.Compiler.Loader;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.painless.lookup.PainlessLookupBuilder;
Expand Down Expand Up @@ -414,7 +415,7 @@ private CompilerSettings buildCompilerSettings(Map<String, String> params) {

value = copy.remove(CompilerSettings.PICKY);
if (value != null) {
compilerSettings.setPicky(Boolean.parseBoolean(value));
compilerSettings.setPicky(Booleans.parseBoolean(value));
}

value = copy.remove(CompilerSettings.INITIAL_CALL_SITE_DEPTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
import org.elasticsearch.common.util.PageCacheRecycler;
import org.elasticsearch.core.Assertions;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.monitor.jvm.JvmInfo;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public class NettyAllocator {

private static final Logger logger = LogManager.getLogger(NettyAllocator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.test.XContentTestUtils;
Expand Down Expand Up @@ -330,7 +331,7 @@ protected static List<ClusterBlock> indexBlocks(String indexName) throws Excepti
@SuppressWarnings("unchecked")
protected static void assertIndexSetting(String indexName, Setting<?> setting, Matcher<Boolean> matcher) throws Exception {
var indexSettings = getIndexSettingsAsMap(indexName);
assertThat(Boolean.parseBoolean((String) indexSettings.get(setting.getKey())), matcher);
assertThat(Booleans.parseBoolean((String) indexSettings.get(setting.getKey())), matcher);
}

protected static ResponseException expectUpdateIndexSettingsThrows(String indexName, Settings.Builder settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.packaging.test.PackagingTestCase;

import java.io.IOException;
Expand Down Expand Up @@ -82,7 +83,7 @@ public static void waitForElasticsearch(Installation installation) throws Except
.lines()
.filter(each -> each.startsWith("xpack.security.enabled"))
.findFirst()
.map(line -> Boolean.parseBoolean(line.split("=")[1]))
.map(line -> Booleans.parseBoolean(line.split("=")[1]))
// security is enabled by default, the only way for it to be disabled is to be explicitly disabled
.orElse(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public static ClusterType parse(String value) {
}

protected static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.suite"));
protected static final boolean FIRST_MIXED_ROUND = Boolean.parseBoolean(System.getProperty("tests.first_round", "false"));
protected static final Version UPGRADE_FROM_VERSION = Version.fromString(System.getProperty("tests.upgrade_from_version"));

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.test.XContentTestUtils;
import org.junit.BeforeClass;
Expand All @@ -33,7 +34,7 @@ public FeatureUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {

@BeforeClass
public static void ensureNotForwardCompatTest() {
assumeFalse("Only supported by bwc tests", Boolean.parseBoolean(System.getProperty("tests.fwc", "false")));
assumeFalse("Only supported by bwc tests", Booleans.parseBoolean(System.getProperty("tests.fwc", "false")));
}

public void testGetFeatureUpgradeStatus() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.common.util.concurrent.CountDown;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.index.Index;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.search.SearchService;
Expand Down Expand Up @@ -607,6 +608,9 @@ private static void mergeResults(
}
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
private static void enrichIndexAbstraction(
ProjectState projectState,
ResolvedExpression resolvedExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.SuppressForbidden;

import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -91,6 +92,9 @@ public static Builder builder(LifecycleExecutionState state) {
.setStepTime(state.stepTime);
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public static LifecycleExecutionState fromCustomMetadata(Map<String, String> customData) {
Builder builder = builder();
String phase = customData.get(PHASE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Constants;
import org.elasticsearch.core.Predicates;
import org.elasticsearch.core.SuppressForbidden;

import java.io.IOException;
import java.net.Inet4Address;
Expand All @@ -32,6 +33,9 @@
* Utilities for network interfaces / addresses binding and publishing.
* Its only intended for that purpose, not general purpose usage!!!!
*/
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public abstract class NetworkUtils {

/** no instantiation */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ public OnDiskState loadOnDiskState(Path dataPath, DirectoryReader reader) throws
);
}

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public OnDiskStateMetadata loadOnDiskStateMetadataFromUserData(Map<String, String> userData) {
assert userData.get(CURRENT_TERM_KEY) != null;
assert userData.get(LAST_ACCEPTED_VERSION_KEY) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.ShardLock;
Expand Down Expand Up @@ -174,6 +175,9 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
private final SearchStatsSettings searchStatsSettings;

@SuppressWarnings("this-escape")
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public IndexService(
IndexSettings indexSettings,
IndexCreationContext indexCreationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.FeatureFlag;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.mapper.IgnoredSourceFieldMapper;
import org.elasticsearch.index.mapper.Mapper;
Expand Down Expand Up @@ -302,6 +303,9 @@ public final class IndexSettings {
return DEFAULT_REFRESH_INTERVAL;
}, new RefreshIntervalValidator(), Property.Dynamic, Property.IndexScope, Property.ServerlessPublic);

@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static class RefreshIntervalValidator implements Setting.Validator<TimeValue> {

static final String STATELESS_ALLOW_INDEX_REFRESH_INTERVAL_OVERRIDE = "es.stateless.allow.index.refresh_interval.override";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.elasticsearch.core.SuppressForbidden;

import java.io.IOException;

Expand All @@ -28,6 +29,9 @@
* cpu resources.</li>
* </ul>
*/
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public class ES819TSDBDocValuesFormat extends org.apache.lucene.codecs.DocValuesFormat {

static final int NUMERIC_BLOCK_SHIFT = 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsFormat;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.index.codec.vectors.OptimizedScalarQuantizer;

import java.io.IOException;
Expand Down Expand Up @@ -85,8 +86,10 @@
* <li>The sparse vector information, if required, mapping vector ordinal to doc ID
* </ul>
*/
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
public class ES818BinaryQuantizedVectorsFormat extends FlatVectorsFormat {

static final boolean USE_DIRECT_IO = Boolean.parseBoolean(System.getProperty("vector.rescoring.directio", "true"));

public static final String BINARIZED_VECTOR_COMPONENT = "BVEC";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ protected IndexWriter createWriter(Directory directory, IndexWriterConfig iwc) t
}

// with tests.verbose, lucene sets this up: plumb to align with filesystem stream
private static final boolean TESTS_VERBOSE = Boolean.parseBoolean(System.getProperty("tests.verbose"));
private static final boolean TESTS_VERBOSE = Booleans.parseBoolean(System.getProperty("tests.verbose", "false"));

private static final boolean SHUFFLE_FORCE_MERGE = Booleans.parseBoolean(
System.getProperty("es.shuffle_forced_merge", Boolean.TRUE.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.lucene.index.IndexFileNames;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.SuppressForbidden;

import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -94,6 +95,9 @@ public enum LuceneFilesExtensions {
* that checks that all encountered file extensions are known to this class.
* In the future, we would like to add a proper plugin extension point for this.
*/
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
private static boolean allowUnknownLuceneFileExtensions() {
return Boolean.parseBoolean(System.getProperty("es.allow_unknown_lucene_file_extensions", "false"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException;
Expand Down Expand Up @@ -589,6 +590,9 @@ protected void doClose() {
* @param threadPool with context where to write the new header
* @return the wrapped action listener
*/
@SuppressForbidden(
reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993"
)
static <T> ActionListener<T> wrapListenerForErrorHandling(
ActionListener<T> listener,
TransportVersion version,
Expand Down
Loading