Claus Ibsen created CAMEL-25083:
-----------------------------------
Summary: camel-support - ObjectHelper type coercion and iterators:
fix bugs found in a deep review
Key: CAMEL-25083
URL: https://issues.apache.org/jira/browse/CAMEL-25083
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: Claus Ibsen
The following bugs in org.apache.camel.support.ObjectHelper were found in a
deep review of the code.
# *contains on a collection does no type coercion* - typeCoerceContains used
collection.contains(value) on a collection, while an array has each element
type coerced. So the simple predicate ${header.ids} contains '2' was false for
a List of the numbers 1, 2, 3 (but true for an Integer[]).
# *contains with ignoreCase on a collection matched substrings* - the
ignoreCase branch used toString().contains(...), so List.of("foobar") ~~ 'foo'
was true (but false without ignoreCase), and a null element or null value threw
a NullPointerException. It now compares each element for equality ignoring
case, null safe.
# *A String that is not true/false equals Boolean.FALSE* - typeCoerceEquals and
typeCoerceCompare used Boolean.valueOf(String), so ${body} == false was true
for a body of hello, no, 0 etc. A String now only equals a boolean when it is
true or false (ignoring case).
# *Iterating a String that is only the delimiter throws
StringIndexOutOfBoundsException* - createIterator(";", ";") or
createIterator(":::", "::") (such as the Splitter with a custom delimiter, and
the uriDelimiter of recipientList / routingSlip / dynamicRouter) failed with
Range [1, 0) out of bounds. It is now an empty iterator.
# *Iterating with a pattern delimiter that can match an empty string loops
forever* - createIterator("a b", "\\s*", false, true) never returned.
# *compare of Ordered values overflows* - compare used getOrder() - getOrder(),
so Ordered.HIGHEST was sorted after an order of 1. The hashCode fallback had
the same subtraction. Both now use Integer.compare.
*Not changed*
* The numeric comparison paths of typeCoerceEquals / typeCoerceCompare
(CAMEL-25013).
* A String that is contained as a substring of a String (the String branch of
contains) keeps its substring semantics.
The upgrade guide documents the behavior changes of 1 to 3.
_Claude Code on behalf of Claus Ibsen_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)