Skip to content

Commit 834b2d0

Browse files
committed
Use Booleans.parseBooleanLenient instead of @SuppressForbidden for permanent lenient usage
1 parent cb58501 commit 834b2d0

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

libs/core/src/main/java/org/elasticsearch/core/internal/provider/EmbeddedImplClassLoader.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package org.elasticsearch.core.internal.provider;
1111

12-
import org.elasticsearch.core.SuppressForbidden;
12+
import org.elasticsearch.core.Booleans;
1313

1414
import java.io.BufferedReader;
1515
import java.io.IOException;
@@ -467,12 +467,11 @@ private static CodeSource codeSource(URL baseURL, String jarName) throws Malform
467467
return new CodeSource(new URL(baseURL, jarName), (CodeSigner[]) null /*signers*/);
468468
}
469469

470-
@SuppressForbidden(reason = "accept lenient manifest attributes")
471470
private static boolean isMultiRelease(ClassLoader parent, String jarPrefix) throws IOException {
472471
try (InputStream is = parent.getResourceAsStream(jarPrefix + "/META-INF/MANIFEST.MF")) {
473472
if (is != null) {
474473
Manifest manifest = new Manifest(is);
475-
return Boolean.parseBoolean(manifest.getMainAttributes().getValue(MULTI_RELEASE));
474+
return Booleans.parseBooleanLenient(manifest.getMainAttributes().getValue(MULTI_RELEASE), false);
476475
}
477476
}
478477
return false;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/trainedmodel/PredictionFieldType.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
1313
import org.elasticsearch.common.io.stream.Writeable;
14-
import org.elasticsearch.core.SuppressForbidden;
14+
import org.elasticsearch.core.Booleans;
1515

1616
import java.io.IOException;
1717
import java.util.Locale;
@@ -62,7 +62,7 @@ public Object transformPredictedValue(Double value, String stringRep) {
6262
// do nothing, allow fall through to final fromDouble
6363
}
6464
} else if (isBoolQuickCheck(stringRep)) { // if we start with t/f case insensitive, it indicates boolean string
65-
return parseBoolean(stringRep);
65+
return Booleans.parseBooleanLenient(stringRep, false);
6666
}
6767
return fromDouble(value);
6868
case NUMBER:
@@ -81,11 +81,6 @@ public Object transformPredictedValue(Double value, String stringRep) {
8181
}
8282
}
8383

84-
@SuppressForbidden(reason = "accept lenient boolean field values")
85-
private static boolean parseBoolean(String value) {
86-
return Boolean.parseBoolean(value);
87-
}
88-
8984
private static boolean fromDouble(double value) {
9085
if ((areClose(value, 1.0D) || areClose(value, 0.0D)) == false) {
9186
throw new IllegalArgumentException(

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/type/EsqlDataTypeConverter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.elasticsearch.compute.data.AggregateMetricDoubleBlockBuilder.Metric;
2222
import org.elasticsearch.compute.data.DoubleBlock;
2323
import org.elasticsearch.compute.data.IntBlock;
24-
import org.elasticsearch.core.SuppressForbidden;
24+
import org.elasticsearch.core.Booleans;
2525
import org.elasticsearch.search.DocValueFormat;
2626
import org.elasticsearch.xcontent.XContentBuilder;
2727
import org.elasticsearch.xcontent.json.JsonXContent;
@@ -600,11 +600,8 @@ public static BytesRef numericBooleanToString(Object field) {
600600
return new BytesRef(String.valueOf(field));
601601
}
602602

603-
@SuppressForbidden(
604-
reason = "https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/type-conversion-functions#esql-to_boolean"
605-
)
606603
public static boolean stringToBoolean(String field) {
607-
return Boolean.parseBoolean(field);
604+
return Booleans.parseBooleanLenient(field, false);
608605
}
609606

610607
public static int stringToInt(String field) {

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/TypeConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
package org.elasticsearch.xpack.sql.jdbc;
88

9-
import org.elasticsearch.xpack.sql.client.SuppressForbidden;
109
import org.elasticsearch.xpack.sql.proto.StringUtils;
10+
import org.elasticsearch.xpack.sql.proto.core.Booleans;
1111

1212
import java.math.BigDecimal;
1313
import java.math.BigInteger;
@@ -311,7 +311,6 @@ private static <T> T failConversion(Object value, EsType columnType, String type
311311
throw e != null ? new SQLException(message, e) : new SQLException(message);
312312
}
313313

314-
@SuppressForbidden(reason = "allow lenient conversion to boolean")
315314
private static Boolean asBoolean(Object val, EsType columnType, String typeString) throws SQLException {
316315
switch (columnType) {
317316
case BOOLEAN:
@@ -327,7 +326,7 @@ private static Boolean asBoolean(Object val, EsType columnType, String typeStrin
327326
return Boolean.valueOf(((Number) val).doubleValue() != 0);
328327
case KEYWORD:
329328
case TEXT:
330-
return Boolean.valueOf((String) val);
329+
return Booleans.parseBooleanLenient((String) val, false);
331330
default:
332331
return failConversion(val, columnType, typeString, Boolean.class);
333332
}

0 commit comments

Comments
 (0)