realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Frozen realm object returns null for realm object field #7597

Closed ayecarranda closed 2 years ago

ayecarranda commented 2 years ago

How frequently does the bug occur?

All the time

Description

I have a Realm object Conversation that has a nullable realm object field user. I have a changesetFlow subscribed to all Conversations in the application. The issue is that every time I access it.collection from within the changesetFlow, and iterate over those Conversation objects, the user field is null on the frozen object when it shouldn't be. I know the user field is non-null from inspecting the local realm file with Realm Studio.

I've traced the issue to the Proxy class, where i can see that isNullLink(columnInfo.userColKey) returns true, and thus I get a null result. I was unable to find documentation of the behavior of realm object and realm list fields in frozen objects - is this expected? If so, what is the workaround - is it to query an 'thawed' version of the object each time?

Conversation
     var user: User? // User is another realm object
where<Conversation>.findAllAsync().toChangesetFlow().onEach {
     it.collection.forEach { frozenConversation ->
           // frozenConversation.user is null
     }
}.launchIn(scope)
// class ConversationRealmProxy.java (proxy for realm object, Conversation
    @Override
    public User realmGet$user() {
        proxyState.getRealm$realm().checkIfValid();
        if (proxyState.getRow$realm().isNullLink(columnInfo.userColKey)) {
            return null;
        }
        return proxyState.getRealm$realm().get(User.class, proxyState.getRow$realm().getLink(columnInfo.userColKey), false, Collections.<String>emptyList());
    }

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

No response

Version

10.8.1

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Android 12

Build environment

Android Studio version: Arctic Fox 2020.3.1 Patch 3 Android Build Tools version: 31 Gradle version: 7.0.2

clementetb commented 2 years ago

If there is a user associated to that conversation it should not be null, even if frozen.

How are you checking the nullity? Is it through the debugger, or are you asserting it?

cmelchior commented 2 years ago

Hi @ayecarranda Is this still a problem?

no-response[bot] commented 2 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.