Skip to content

Conversation

@dogi
Copy link
Member

@dogi dogi commented Nov 9, 2025

No description provided.

google-labs-jules bot and others added 2 commits November 9, 2025 10:37
The `UserProfileDbHandler.userModel` property already returns an unmanaged copy of the `RealmUserModel`.

The `onCreate` method in `BaseTeamFragment` was attempting to call `mRealm.copyFromRealm()` on this already unmanaged object, causing an `IllegalArgumentException` and crashing the app when opening team details.

This commit removes the redundant and erroneous `copyFromRealm` call, fixing the crash. The `user` property is now assigned the unmanaged `RealmUserModel` directly.
@dogi
Copy link
Member Author

dogi commented Nov 9, 2025

how about

val userModel: RealmUserModel? get() = getUserModelCopy()

You've pointed to the exact right place!

That line is indeed where the first copy of the RealmUserModel is made. Let's look at the context:

// in UserProfileDbHandler.kt

fun getUserModelCopy(): RealmUserModel? {
val userId = settings.getString("userId", null)?.takeUnless { it.isBlank() } ?: return null
return realmService.withRealm { realm ->
realm.where(RealmUserModel::class.java)
.equalTo("id", userId)
.or()
.equalTo("_id", userId)
.findFirst()
?.let { realm.copyFromRealm(it) } // <-- This is the line you linked
}
}
This line is not redundant; it's actually performing a very important function. Here's why it's necessary:

Thread Safety: Realm objects are "thread-confined," which means a Realm object fetched on one thread cannot be accessed on a different thread. Doing so would cause a crash.
Decoupling: The UserProfileDbHandler is a central service used by many different parts of the application. By providing an unmanaged copy (copyFromRealm), it gives the rest of the app a safe, plain Kotlin object to work with. The fragment that receives this object doesn't have to worry about which thread it's on or whether the Realm instance is still open.
The problem wasn't that this line existed. The problem was that BaseTeamFragment took the object that this line already copied and tried to copy it a second time. The crash happened because you can't run copyFromRealm on an object that is already a copy.

So, to summarize:

The line in UserProfileDbHandler is correct and necessary for creating a safe, shareable user object.
The line in BaseTeamFragment was the bug because it was an unnecessary and invalid attempt to re-copy that object.

@dogi
Copy link
Member Author

dogi commented Nov 9, 2025

#8911 was not fully tested

@dogi dogi changed the title Version3704 (fixes #8982) teams: smoother base user profile handling (fixes #8982) Nov 10, 2025
@dogi dogi merged commit 0fa4f08 into master Nov 10, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants