Skip to content

BinaryComparator: a BOOLEAN compared against a timestamp type answers one way forwards and throws NullPointerException backwards #7754

Closed

Description

@lvca

Found during the review of PR #7750 (the #7628 comparator work), deliberately left out of it because it is a different question with a different answer, and because it fails loudly rather than silently.

The defect

BinaryComparator.compare answers a BOOLEAN-versus-timestamp comparison correctly in one direction and throws NullPointerException in the other, for all five temporal types:

final BinaryComparator comparator = new BinaryComparator();

// BOOLEAN first: fine. The BOOLEAN branch delegates to compareNarrowIntegral, which treats true as 1.
comparator.compare(true, BinaryTypes.TYPE_BOOLEAN, 5L, BinaryTypes.TYPE_DATETIME);   // -1

// Timestamp first: NullPointerException
comparator.compare(5L, BinaryTypes.TYPE_DATETIME, true, BinaryTypes.TYPE_BOOLEAN);   // throws

Reproduced against TYPE_DATE, TYPE_DATETIME, TYPE_DATETIME_SECOND, TYPE_DATETIME_MICROS and TYPE_DATETIME_NANOS.

Why

The DATE/DATETIME* arm of compare converts both operands with DateUtils.dateTimeToTimestampInferringStringPrecision, which has no Boolean case and returns null; unboxing that Long into the long local NPEs. The opposite direction never reaches it, because the TYPE_BOOLEAN arm of compare maps the boolean to 1/0 and hands it to compareNarrowIntegral.

So the two directions disagree about whether the comparison is meaningful at all - one of them answers, the other crashes.

Why it is not simply a missing case

Deciding what boolean versus timestamp should MEAN is the actual question, and it is not obvious:

Suggested fix

Pick one of the two answers deliberately, then make both directions implement it:

  • if the comparison stays meaningful, give the DATE/DATETIME* arm a BOOLEAN case mapping to 1/0, mirroring the TYPE_BOOLEAN arm;
  • if it does not, refuse it from both arms with the IllegalArgumentException the unsupported-pair fall-through already raises, and drop TYPE_BOOLEAN from compareNarrowIntegral/compareWideningLong's accepted set.

Either way the regression test should assert both directions for all five temporal types, the way Issue7628ExactIntegralComparisonTest does for the numeric ones.

Scope

Pre-existing: it predates PR #7750 and affects the untouched DATE/DATETIME arms identically, so it is not a regression from that work.

Activity

  1. self-assigned this
    on Sep 17, 2026
  2. added
    engine
    on Sep 17, 2026
  3. added a commit that references this issue on Sep 17, 2026
  4. added this to the 26.10.1 milestone on Sep 17, 2026
  5. added
    severity:major
    on Sep 19, 2026
  6. added
    in progress
    on Sep 30, 2026
  7. added 5 commits that reference this issue on Sep 30, 2026
  8. lvca commented on Sep 30, 2026

    @lvca
    MemberAuthor

    Fixed in #8742 (26.10.1). Comparing a BOOLEAN with a date or timestamp now fails the same way in both directions, with a clear "Comparison between type ... not supported" error instead of a NullPointerException in one direction. SQL <, >, <=, >= and BETWEEN, and the native select() API, treat such a pair as "no match". A native orderBy on a column mixing booleans and timestamps now raises the error instead of sorting arbitrarily.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  9. removed
    in progress
    on Sep 30, 2026
  10. added a commit that references this issue on Sep 30, 2026
  11. added 5 commits that reference this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineseverity:major

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions