Skip to content

Native Select ilike throws NullPointerException on a record that does not carry the property, while like and SQL ILIKE answer false #8170

Closed

Description

@ruispereira

Summary

On the native Select API, ilike throws a NullPointerException for any record that does not carry the
property being matched, so a single record with an optional property aborts the whole query instead of simply
not matching. like, one enum constant below and otherwise identical, answers false for the same record,
and SQL's ILIKE answers correctly too.

SelectOperator.ilike casts the result of SelectExecutor.evaluateValue(...) to String and calls
.toLowerCase(Locale.ENGLISH) on it with no null check. evaluateValue returns null for a property the
record does not have, so the .toLowerCase call NPEs. like hands the same possibly-null value straight to
QueryHelper.like, which starts by rejecting null and returning false - which is why only ilike crashes.

This is the same "a record that lacks the property" family #8049 normalised for lt/le/gt/ge/between
(all five now evaluate both sides once and return false if either is null). ilike is the one operator left
where a missing property is a crash rather than a non-match.

Where (HEAD 9a88be7)

engine/src/main/java/com/arcadedb/query/select/SelectOperator.java:154-164 - both operands are cast and
dereferenced unguarded:

  ilike("ilike", false, 1) {
    @Override
    Object eval(final Document record, final Object left, final Object right) {
      // BOTH sides fold with the same locale. The right-hand one used to use the JVM default, so on a Turkish
      // server an ILIKE whose pattern carried an 'I' folded differently from the value it was matched against and
      // stopped matching (issue #7900).
      return QueryHelper.like(((String) SelectExecutor.evaluateValue(record, left)).toLowerCase(Locale.ENGLISH),
          ((String) SelectExecutor.evaluateValue(record, right)).toLowerCase(Locale.ENGLISH),
          GlobalConfiguration.COMMAND_REGEX_TIMEOUT.getValueAsLong(record.getDatabase()));
    }
  },

against the sibling immediately below it, engine/src/main/java/com/arcadedb/query/select/SelectOperator.java:166-173,
which passes the value through without dereferencing it:

  like("like", false, 1) {
    @Override
    Object eval(final Document record, final Object left, final Object right) {
      return QueryHelper.like((String) SelectExecutor.evaluateValue(record, left),
          (String) SelectExecutor.evaluateValue(record, right),
          GlobalConfiguration.COMMAND_REGEX_TIMEOUT.getValueAsLong(record.getDatabase()));
    }
  },

and the null rule that makes like safe,
engine/src/main/java/com/arcadedb/query/sql/executor/QueryHelper.java:49-52:

  public static boolean likeUntil(String currentValue, String value, final long deadlineNanos) {
    if (currentValue == null || value == null || (currentValue.isEmpty() ^ value.isEmpty()))
      // EMPTY/NULL PARAMETERS
      return false;

For comparison, the rule #8049 established for the ordering operators
(engine/src/main/java/com/arcadedb/query/select/SelectOperator.java:107-115):

  lt("<", false, 1) {
    @Override
    Object eval(final Document record, final Object left, final Object right) {
      final Object leftValue = SelectExecutor.evaluateValue(record, left);
      final Object rightValue = SelectExecutor.evaluateValue(record, right);
      if (leftValue == null || rightValue == null)
        return false;
      return BinaryComparator.compareTo(leftValue, rightValue) < 0;
    }
  },

Repro

A document type D with a STRING property s, two records: one with s = "abc", one that never set s at
all (it carries an unrelated property). Then the same predicate three ways:

  native s like 'a%'  = 1
  native s ilike 'A%' -> java.lang.NullPointerException: Cannot invoke "String.toLowerCase(java.util.Locale)" because the return value of "com.arcadedb.query.select.SelectExecutor.evaluateValue(com.arcadedb.database.Document, Object)" is null
  sql    s ilike 'A%' = 1

like and SQL ILIKE both answer 1 (the record that has the property matches, the one that does not is
skipped); the native ilike never returns an answer at all. The query is driven through the public fluent
API, db.select().fromType("D").where().property("s").ilike().value("A%").count().

Suggested fix

Give ilike the same shape like already has - evaluate both sides once, and answer false when either is
null, before folding case:

      final Object leftValue = SelectExecutor.evaluateValue(record, left);
      final Object rightValue = SelectExecutor.evaluateValue(record, right);
      if (leftValue == null || rightValue == null)
        return false;
      return QueryHelper.like(((String) leftValue).toLowerCase(Locale.ENGLISH),
          ((String) rightValue).toLowerCase(Locale.ENGLISH),
          GlobalConfiguration.COMMAND_REGEX_TIMEOUT.getValueAsLong(record.getDatabase()));

That keeps the #7900 single-locale folding intact and makes ilike agree with like, with SQL ILIKE and
with the rule #8049 wrote down for the ordering operators. A regression test should assert ilike over a type
where only some records carry the property, the same three ways (SQL, no index, index) the
Issue8049SelectNullOrderingComparisonTest uses.

Scope / confidence

Reproduced end to end against this HEAD with the code built from it; the exception text above is the run's own
output. Pre-existing, not introduced by #8094 - that PR normalised the five ordering operators and did not
touch ilike. Impact is high for the native API: a query is not merely wrong, it fails, and it fails only
once a record without the property happens to be in the scan, so it can pass in development and throw in
production. The equivalent SQL path is unaffected.

Activity

  1. added
    engine
    severity:major
    on Sep 22, 2026
  2. added this to the 26.10.1 milestone on Sep 22, 2026
  3. added
    in progress
    on Sep 22, 2026
  4. self-assigned this
    on Sep 22, 2026
  5. added a commit that references this issue on Sep 23, 2026
  6. lvca commented on Sep 23, 2026

    @lvca
    Member

    Fixed in #8226, will be released in 26.10.1.

    The native like and ilike operators now use exactly the same logic as SQL LIKE/ILIKE. A record without the property (or a null pattern) simply doesn't match instead of throwing. As a bonus, a non-string value is now matched by its text instead of failing, and a list property matches when any of its items does, the same as in SQL.


    ❤️ 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.

  7. removed
    in progress
    on Sep 23, 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