Skip to content

Commit 993a9cd

Browse files
committed
Merge pull request realm#1729 from realm/my/isNull-nested-query-for-link-field
throws IllegalArgumentException if isNull/isNotNull is called for unsupported field.
2 parents 7d88d70 + eaf9439 commit 993a9cd

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Added Realm.isEmpty().
33
* Fixed a bug making it impossible to convert a field to become required during a migration (#1695).
44
* Fixed a bug making it impossible to read Realms created using primary keys and created by iOS (#1703).
5+
* RealmQuery.isNull() and RealmQuery.isNotNull() now throw IllegalArgumentException instead of RealmError if the fieldname is a linked field and the last element is a link (#1693).
56

67
0.84.1
78
* Updated Realm Core to 0.94.4

realm/realm-jni/src/io_realm_internal_TableQuery.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ JNIEXPORT void JNICALL Java_io_realm_internal_TableQuery_nativeIsNull(
14611461
} else {
14621462
switch (col_type) {
14631463
case type_Link:
1464-
pQuery->and_query(src_table_ref->column<Link>(S(column_idx)).is_null());
1464+
ThrowException(env, IllegalArgument, "isNull() by nested query for link field is not supported.");
14651465
break;
14661466
case type_LinkList:
14671467
// Cannot get here. Exception will be thrown in TBL_AND_COL_NULLABLE
@@ -1604,7 +1604,7 @@ JNIEXPORT void JNICALL Java_io_realm_internal_TableQuery_nativeIsNotNull
16041604
else {
16051605
switch (col_type) {
16061606
case type_Link:
1607-
pQuery->and_query(src_table_ref->column<Link>(S(column_idx)).is_not_null());
1607+
ThrowException(env, IllegalArgument, "isNotNull() by nested query for link field is not supported.");
16081608
break;
16091609
case type_LinkList:
16101610
// Cannot get here. Exception will be thrown in TBL_AND_COL_NULLABLE

realm/realm-library/src/androidTest/java/io/realm/RealmQueryTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,14 +1103,14 @@ public void testIsNullOnLinkField() {
11031103
assertEquals(2, testRealm.where(NullTypes.class).isNull(
11041104
NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_DATE_NULL).count());
11051105
// 11 Object
1106-
// FIXME: Currently not support by Realm core
1106+
// FIXME: Currently, Realm Core does not support isNull() query for nested link field.
11071107
//assertEquals(1, testRealm.where(NullTypes.class).isNull(
11081108
// NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_OBJECT_NULL).count());
11091109
try {
11101110
testRealm.where(NullTypes.class).isNull(
1111-
NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_OBJECT_NULL).count();
1111+
NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_OBJECT_NULL);
11121112
fail();
1113-
} catch (RealmError ignored) {
1113+
} catch (IllegalArgumentException ignored) {
11141114
}
11151115
}
11161116

@@ -1228,12 +1228,12 @@ public void testIsNotNullOnLinkField() {
12281228
// 11 Object
12291229
//assertEquals(1, testRealm.where(NullTypes.class).isNotNull(
12301230
// NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_OBJECT_NULL).count());
1231-
// FIXME: Currently, link queries don't work fully on null
1231+
// FIXME: Currently, Realm Core does not support isNotNull() query for nested link field.
12321232
try {
12331233
testRealm.where(NullTypes.class).isNotNull(
1234-
NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_OBJECT_NULL).count();
1234+
NullTypes.FIELD_OBJECT_NULL + "." + NullTypes.FIELD_OBJECT_NULL);
12351235
fail();
1236-
} catch (RealmError ignored) {
1236+
} catch (IllegalArgumentException ignored) {
12371237
}
12381238
}
12391239

0 commit comments

Comments
 (0)