Skip to content

Jackson 3: unguarded textValue()/asBoolean() throw where Jackson 2 returned defaults (JoinFunction, BooleanUtils) #434

Description

@wnm3

Summary

Two unguarded coercion call sites changed behavior under the Jackson 3 migration (#430, PR #431). Jackson 3 tightened textValue() (now stringValue(), throws for any non‑String node) and the no‑arg asBoolean() (throws for non‑coercible node types). Jackson 2 returned null / false respectively. These lines were not changed by the migration, so behavior flipped from "return default" to "throw tools.jackson.databind.node.JsonNodeException".

Not caught by the test suite.

Where & reproductions

1. JoinFunction.java:121 — textValue() on non‑string inner element

} else if (element.isArray()) {
    for (Iterator<JsonNode> it = ((ArrayNode) element).iterator(); it.hasNext();) {
        stringJoiner.add(it.next().textValue());   // <-- no isTextual() guard
    }
}

Note the outer element at line 117 is guarded (element.isTextual()), but the inner loop at 121 is not.

  • Repro: $join([[1, 2]])
  • Jackson 2: textValue() returns null → StringJoiner appends "null" → result "nullnull".
  • Jackson 3: throws JsonNodeException.

2. BooleanUtils.java:89 — asBoolean() on a BinaryNode

case BINARY:
    return node.asBoolean();
  • Jackson 2: returns the default false for a BinaryNode.
  • Jackson 3: throws JsonNodeException.
  • Lower reachability (requires a BinaryNode reaching $boolean(...)), but it is an unguarded no‑arg coercion of exactly the kind this migration must audit.

Verified empirically against jackson‑databind 3.2.0

IntNode(5).textValue()    -> THROWS JsonNodeException
BinaryNode.asBoolean()    -> THROWS JsonNodeException

Related minor note (low priority)

ArrayUtils.compare (line 105, changed in this PR) now uses asText(""). For a container node this correctly restores the Jackson‑2 "", but for a POJONode it returns "" where Jackson 2 returned the POJO's toString(). Reachability is very low ($sort over a regex POJONode is not a realistic user path), so this is noted rather than treated as a separate defect.

Suggested fix

Add an isTextual() guard at JoinFunction:121 (matching line 117) — decide whether a non‑string inner element should stringify via the JSONata number/string rules or raise the existing ERR_MSG_ARG1_ARR_STR. For BooleanUtils:89, return false explicitly for the BINARY case rather than delegating to the now‑throwing asBoolean().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions