Realm-java: The getter for a RealmList returns null.

Created on 24 Mar 2017  路  22Comments  路  Source: realm/realm-java

Goal

The following query which returns a RealmList sometimes returns null which is unexpected.

realm.where(SearchItem.class)
.equalTo("query", searchQuery)
.findFirst()
.getArticles();

Model object:

public class SearchItem extends RealmObject {

@PrimaryKey
private Long id;

@Required
private String query;

private int priority;

private RealmList<Article> articles;
private RealmList<Folder> folders;
private RealmList<Producer> producers;
private RealmList<Brand> brands;

.... getters/setters

public RealmList<Article> getArticles() {
    return articles;
}

}

Expected Results

Documentation states: The getter for a RealmList will never return null. The returned object is always a list but the length might be zero.

Actual Results

Null value returned

Steps & Code to Reproduce

Version of Realm and tooling

Realm version(s): 3.0.0

Realm sync feature enabled: no

Android Studio version: 2.3

Which Android version and device: OnePlus 3T, Android 7

T-Help

All 22 comments

Is findFirst() returning null? What is the backtrace?

Note, It can return null if the object is unmanaged.

are you sure it is not findFirst() that returned null?

sorry, it was findFirst() that sometimes returned null because an async write transaction was sometimes already completed and sometimes not

Try and just initialize the list to the resolve this issue that occours on unmanaged object.

private RealmList<RmCategory> subCategories = new RealmList<>();

how is that according to the documentation it should be handled for me

I face the same issue

public class Dog : RealmObject
{
public string Name { get; set; }
}

public class Person : RealmObject
{
// ... other property declarations
public IList Dogs { get; }
}

@minaairsupport your code is for Realm Xamarin, you should ask at https://github.com/realm/realm-dotnet/

Sorry but I think its the same issue

No it's not. It is a completely different binding.

Maybe my last answer from May 2017 goes for Xamarin implementation, too.

I tried by the way and the app crashes , have you tried something else

I'd try reading the crash stack trace for possible error messages that can help deciding what the cause of the error is.

11-05 05:38:28.314 D/Mono ( 6876): Assembly Ref addref CB.Core.Conversion[0xddc89160] -> CB.Core.Common[0xf3cf1e20]: 7
Resolved pending breakpoint at 'ConvertorHelper.cs:84,1' to CB.Core.Entities.FlightListItem CB.Core.Conversion.ConvertorHelper.FlightListItemModelConvertor (CB.Core.Models.FlightListItem item) [0x00160].
11-05 05:38:28.380 F/ ( 6876): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mono/mini/unwind.c:635, condition `cfa_reg != -1' not met
11-05 05:38:28.381 F/libc ( 6876): Fatal signal 6 (SIGABRT), code -6 in tid 7076 (Thread Pool Wor)

Now if I look for this error online, it says that a possible workaround is to use English system locale on the system that compiles the C# code.

could you provide link ?

thanks for link but is it normal to find IList with null and cant add to it

That is not related to the error message you posted at all

Please stop spamming this closed issue with unregarding stuff.

yea this happen when I try silviokuehn answer
private RealmList subCategories = new RealmList<>();
I do the same
private RealmList subCategories => subCategories ?? new RealmList<>();

Bring it over to realm-dotnet.

I will stop answering anything beyond this point.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mithrann picture mithrann  路  3Comments

AAChartModel picture AAChartModel  路  3Comments

bryanspano picture bryanspano  路  3Comments

wyvern610 picture wyvern610  路  3Comments

CNyezi picture CNyezi  路  3Comments