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.

Evaluate Expression in Android Studio does not work correctly with Realm Objects

See original GitHub issue

Typing this in the Evaluate Expression window in the debugger in Android studio aRealmObject.someRealmList.first() throws a NoSuchElementException: List is empty, when the realm list really isn’t empty.

Android Studio Bumblebee | 2021.1.1 Patch 1 Build #AI-211.7628.21.2111.8139111, built on February 2, 2022 Runtime version: 11.0.11+0-b60-7590822 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 12.0.1 GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 16 Registry: external.system.auto.import.disabled=true Non-Bundled Plugins: com.chimerapps.proguard-retrace (1.0.1), com.cmgapps.intellij.proguard-retrace-unscambler (1.3.0), wu.seal.tool.jsontokotlin (3.7.2), org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40)

realm version 0.7.0 (we currently can’t upgrade higher than this due to kotlin 1.6 issues.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cmelchiorcommented, Mar 4, 2022

After some more digging. I now suspect it is a problem in our generated code somehow:

class Author : RealmObject {
    var firstName: String? = ""
    var lastName: String? = ""
    var age: Int? = 0

    @Ignore
    var ignoreMe: String = ""
        get() {
            return "Hello from Getter: ${field}"
        }
        set(value) {
            field = value
        }
}

In this class, the ignoreMe field works as expected when evaluating, while all the managed properties do not.

There is a few changes in the generated IR, especially this block is present in our generated accessors BLOCK type=kotlin.Nothing origin=null while it isn’t in the default one…but not sure what it does nor if it even makes a difference.

1reaction
cmelchiorcommented, Mar 4, 2022

The same problem is also in present in Android Studio Dolphin Canary 5.

I did find work-around though. If you switch to Java in the dropdown, you can manually call the getters, which will do the correct thing, e.g. book.getAuthors() instead of book.authors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't watch realmObjects in debug (Android Studio) [duplicate]
I recently started using Realm. The problem is sometimes I have to use dubug mode to solve some bugs. Thing is realmObjects always...
Read more >
Define relationships between objects - Android Developers
In Room, there are two ways to define and query a relationship between entities: you can model the relationship using either an intermediate ......
Read more >
Debugging - Java SDK — Realm - MongoDB
The Android Studio debugger can provide misleading values for Realm object fields. For correct values, you can watch accessor values instead, ...
Read more >
Realm Auto-Updated Objects: What you need to know - Medium
It cannot show you the values of fields inside your model objects. Using the debugger's 'Evaluate Expression' does not solve this for me....
Read more >
realm-core/CHANGELOG.md at master - GitHub
CTAD doesn't work through aliases until C++20, so any code like util::Optional(EXPRESSION) without the <Type> template arguments will need to switch to ...
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