question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

equalTo() fails to find null values on an indexed field if using Case.INSENSITIVE

See original GitHub issue

It appears that Realm versions from 3.1.3 onward have a bug where using equalTo() on a query no longer finds indexed fields which have null values, but only when the Case.INSENSITIVE flag is being used. Using Case.SENSITIVE (the default) still works.

In the Realm Java changelog for 3.1.3 we can see the following under enhancements:

Upgraded to Realm Core 2.6.1.

We can see in the Realm Core changelog for 2.6.0 the following, which looks like it could be the culprit:

Made case insensitive queries use the new index based case insensitive search. PR #2486

Expected Results

I would expect to be able to find records whose values for the field we’re searching on are null

Actual Results

No records are found

Code Sample

RealmTest.class is a subclass of RealmObject and defines test_field like so:

    @Index
    private String test_field;

Now the query:

    Realm realm = Realm.getDefaultInstance();

    String searchString = "test";
    realm.where(RealmTest.class)
        .equalTo("test_field", searchString, Case.INSENSITIVE)
        .findAll();
// 3.1.0 behaviour: returns all results where test_field has a value of "test" ✅
// 3.1.3 behaviour: returns all results where test_field has a value of "test" ✅


    searchString = null;
    realm.where(RealmTest.class)
        .equalTo("test_field", searchString, Case.INSENSITIVE)
        .findAll();
// 3.1.0 behaviour: returns all results where test_field has a value of null ✅
// 3.1.3 behaviour: does NOT return results where test_field has a value of null ❌

Again, this bug is only seen when Case.INSENSITIVE is used, which makes me suspicious that Realm-Core PR #2486 might be the cause of this issue, but I’m not sure.

Version of Realm and tooling

Realm version(s): >= 3.1.3

Realm sync feature enabled: no

Android Studio version: 2.3.3

Which Android version and device: 8.0, Pixel.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
morrisseyaicommented, Sep 22, 2017

@ironage brilliant, thanks for the super fast turnaround on this one!

0reactions
cmelchiorcommented, Oct 2, 2017

Fixed in 4.0.0-RC1. Closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

linq case insensitive (without toUpper or toLower)
Use String.Equals with the appropriate parameters to make it case insensitive mySource.Where(s => String.Equals(s, "Foo", StringComparison.
Read more >
Case Sensitive Search on a Case Insensitive SQL Server
Solution. One option is to specify the collation for the query to use a case sensitive configuration. Let's show an example of a...
Read more >
Case sensitivity (Reference) - Prisma
Case sensitivity. Case sensitivity affects filtering and sorting of data, and is determined by your database collation. Sorting and filtering data ...
Read more >
Functions for Use in SELECT and WHERE Clauses - O'Reilly
An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for the operators and functions involved in...
Read more >
How To Search
Want to match an empty/null value for a field? You'll need to remove the colon and then write "is null". For example, quickly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found