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.

Crash on deleting realm after migrating to 4.1.1 from 3.3.1

See original GitHub issue

We are using below code to to open realm instance. It used to work fine for version 3.1.1 Idea is that we have some migrations for last two three versions but for version before that we dont so it throws exception or in case migration fails we delete that current realm and open again.

this used to work fine in 3.1.1 how ever we just upgraded to 4.1.1 last sprint and after it we are seeing a-lot of crashes.

            Realm.init(context);
            RealmConfiguration configuration = new RealmConfiguration.Builder()
                    .schemaVersion(<version>)
                    .migration(<migrator>)
                    .build();

            try {
                defaultInstance = Realm.getInstance(configuration );
            } catch (IllegalArgumentException | IllegalStateException | RealmMigrationNeededException ex) {
                Realm.deleteRealm(configuration);
                defaultInstance = Realm.getInstance(configuration);
            }

Expected Results

it should not crash

Actual Results

This is the exception we are getting

Caused by java.lang.IllegalStateException: It's not allowed to delete the file associated with an open Realm. Remember to close() all the instances of the Realm before deleting its file: /data/data/com.x.x/files/default.realm
       at io.realm.Realm.io.realm.BaseRealm.deleteRealm(SourceFile:14624)
       at com.x.x.x.RealmManager.getDefaultInstance(SourceFile:52)

Version of Realm and tooling

Realm version(s): 4.1.1

Realm sync feature enabled: yes/no

Android Studio version: 3.0.0

Which Android version and device: no specific version happening on almost every os

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cmelchiorcommented, Nov 28, 2017

I just tried to write the following unit test:

    @Test
    public void deleteRealm_afterMigrationFailed() {
        RealmConfiguration config = configFactory.createConfigurationBuilder()
                .assetFile("default0.realm")
                .build();

        // First open Realm in dynamic mode to ensure that it is copied to disk
        DynamicRealm.getInstance(config).close();

        try {
            // Then attempt to open Realm normally which should throw
            Realm.getInstance(config);
            fail();
        } catch (RealmMigrationNeededException e) {
            assertTrue(Realm.deleteRealm(config));
        }
    }

It parses. Have you tried printing the values of Realm.getGlobalInstanceCount(config) as the first thing in your try/catch?

0reactions
RemyTabardelcommented, Dec 4, 2017

in 4.2.1, no date at the moment, i’m waiting for that too =p https://github.com/realm/realm-java/blob/master/CHANGELOG.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm: Create reactive mobile apps in a fraction ... - MongoDB
The path to a local Realm's file location; The migration function, if a Realm's schemas change between revisions and must be updated; Configuring...
Read more >
I have trouble with the latest Android Studio Gradle Update 3.3.1
The question is not related to 'Butterknife' at all as because after removing it's dependencies, the warnings were still there.
Read more >
Hazelcast IMDG Release Notes
Hazelcast IMDG Open Source Edition Release Notes lists the new features, enhancements and fixed issues for each Hazelcast IMDG release.
Read more >
Create reactive mobile apps in a fraction of the time - Realm
Apps using Realm can target: iOS 8 or later, OS X 10.9 or later & WatchKit. ... Make sure that you remove the...
Read more >
1.24 - Foreman :: Manual
The Foreman installer uses Puppet (4 or later required) to install Foreman. ... Remove DNS entries from FreeIPA when deleting hosts from realm....
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