realm / realm-java

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

Multiple `@RealmModule`s with same class name can cause erroneous schema definitions #7860

Closed rorbech closed 11 months ago

rorbech commented 11 months ago

How frequently does the bug occur?

Sometimes

Description

Defining a library and an app module with an @RealmModule with a equal class name can cause configurations to pick up the wrong schema. Both @RealmModule-classes must have the same name (but needs to be in separate packages to avoid class name overlaps).

Library:

package io.realm.library
@RealmModule(library = true, allClasses = true)
class Module

App:

package io.realm.app
@RealmModule(allClasses = true)
class Module

Due to the layout of our mediators both of the above modules will generate a mediator class named io.realm.ModuleMediator. For some reason compilation of the final app will silently discard one of the classes instead of throwing a compilation error.

Note: Somehow the project setup can be dictating how the final app is build and which of the two modules that will end up in the final package. Thus, it is not guaranteed to fail.

Similar issue reported in #7855

Stacktrace & log output

No response

Can you reproduce the bug?

Sometimes

Reproduction Steps

No response

Version

1.17.0

What Atlas App Services are you using?

Both Atlas Device Sync and Atlas App Services

Are you using encryption?

No

Platform OS and version(s)

Android API 33

Build environment

Android Build Tools version: 8.1.4 Gradle version: 8.3

rorbech commented 11 months ago

Since there is an immediate workaround by just avoiding name overlaps, we have no immediate plans of fixing this.

andriy-svirskyy commented 11 months ago

How about inability to avoid name overlaps in third party libraries provided without the source code?

rorbech commented 11 months ago

Hi @andriy-svirskyy. It will of course be a problem if you don't control source code of external libraries. Do you have such use cases and with which libraries?

On this note, we are working on Realm Kotlin which does not have such issues. Have you consider migrating to that instead?

andriy-svirskyy commented 11 months ago

Hi @rorbech, afraid there are no migration plans to Kotlin.