Add hint to documentation that RealmMigration implementation should override equals() and hashCode()
See original GitHub issueProblem
I don’t understand the reason, but under some circumstances concerning multithreading the following exception will not be printed:
java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file. The most likely cause is that equals() and hashCode() are not overridden in the migration class: package.MigrationClass
at io.realm.RealmCache.validateConfiguration(RealmCache.java:450)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:339)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:281)
at io.realm.Realm.getInstance(Realm.java:346)
Instead the background thread will get terminated without any feedback. I produced this stacktrace by accident, while making a call to my realm database on the main thread instead of on a background thread. Even if you can’t figure out the reason for this either it would be awesome to have an hint in the documentation that an implementation of “RealmMigration” should override equals and hashcode. This would have saved me a couple of hours 😃
Greets, djuelg
Version of Realm and tooling
Realm version(s): 3.7.2
Realm sync feature enabled: no
Android Studio version: 2.3.3
Which Android version and device: OnePlus 3T (API 25), Emulator (API26)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Why do I need to override the equals and hashCode methods ...
Joshua Bloch says on Effective Java. You must override hashCode() in every class that overrides equals(). Failure to do so will result in...
Read more >Why to Override equals(Object) and hashCode() method
Case 1: Overriding both equals(Object) and hashCode() method ... hashCode(), which will prevent your class from functioning properly in ...
Read more >Working With hashcode() and equals() - DZone Java
In order to achieve a fully working custom equality mechanism, it is mandatory to override hashcode() each time you override equals(). Follow ...
Read more >Ultimate Guide to Implementing equals() and hashCode() with ...
Overriding the equals() and hashCode() methods of your entities is harder than it seems and ... 1 When and Why you need to...
Read more >Generate Overrides for equals(), hashCode() and toString()
You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select equals() and hashCode() . You can also use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It is often a source of confusion, I agree, which is also why the exception is so explicit about it, but consider the following case:
This is of course constructed but shows that you might parse in two different implementations of a migration if we just compare e.g. the class. Some really subtle bugs could happen because of this.
I don’t recall ever seeing a RealmMigration class with state like that though, so one could argue that we should just check for the class and document the corner case.
On the other hand, people should not be creating multiple RealmConfigurations in the first place.
https://github.com/djuelg/Neuronizer/blob/master/app/src/main/java/de/djuelg/neuronizer/storage/PreviewRepositoryImpl.java