You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/09/20 15:05:27 UTC
[camel] branch main updated: (chores) consolidate valid boolean check (#11495)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4eace066acb (chores) consolidate valid boolean check (#11495)
4eace066acb is described below
commit 4eace066acb7b2cfa25f13ea4ec0ca4c8e838efb
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Wed Sep 20 17:05:20 2023 +0200
(chores) consolidate valid boolean check (#11495)
---
.../org/apache/camel/catalog/impl/AbstractCamelCatalog.java | 5 +++--
.../src/main/java/org/apache/camel/util/ObjectHelper.java | 13 +++++++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
index abe4bd56d5f..2061558b099 100644
--- a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
+++ b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
@@ -53,6 +53,7 @@ import org.apache.camel.tooling.model.JsonMapper;
import org.apache.camel.tooling.model.LanguageModel;
import org.apache.camel.tooling.model.MainModel;
import org.apache.camel.tooling.model.OtherModel;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.URISupport;
@@ -297,7 +298,7 @@ public abstract class AbstractCamelCatalog {
// is boolean
if (!multiValue && !valuePlaceholder && !lookup && "boolean".equals(row.getType())) {
// value must be a boolean
- boolean bool = "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
+ boolean bool = ObjectHelper.isBoolean(value);
if (!bool) {
result.addInvalidBoolean(name, value);
}
@@ -1177,7 +1178,7 @@ public abstract class AbstractCamelCatalog {
// is boolean
if (!optionPlaceholder && !lookup && "boolean".equals(row.getType())) {
// value must be a boolean
- boolean bool = "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
+ boolean bool = ObjectHelper.isBoolean(value);
if (!bool) {
result.addInvalidBoolean(longKey, value);
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
index b66e03ad803..29f57fcdf68 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -123,14 +123,14 @@ public final class ObjectHelper {
}
if (value instanceof byte[]) {
String str = new String((byte[]) value);
- if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str)) {
+ if (isBoolean(str)) {
return Boolean.valueOf(str);
}
}
if (value instanceof String) {
// we only want to accept true or false as accepted values
String str = (String) value;
- if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str)) {
+ if (isBoolean(str)) {
return Boolean.valueOf(str);
}
}
@@ -1322,6 +1322,15 @@ public final class ObjectHelper {
}
}
+ /**
+ * Checks whether the given string is a valid boolean value (i.e.; either "true" or "false") ignoring its case
+ * @param str the string to evaluate
+ * @return true if it is a valid boolean value or false otherwise
+ */
+ public static boolean isBoolean(String str) {
+ return "true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str);
+ }
+
/*
* NOTE: see CAMEL-19724. We log like this instead of using a statically declared logger in order to
* reduce the risk of dropping log messages due to slf4j log substitution behavior during its own