Realm-java: BadVersionException

Created on 3 Jan 2016  Â·  47Comments  Â·  Source: realm/realm-java

Hey, guys. I keep getting this exception. I am using 0.87.1 version of Realm(and I use Realm as a singleton).

My situation looks like this: there is navigation button which starts a fragment, which makes an async query for objects in onStart() method. This exception rises when user spams this navigation button or just makes fast transactions between fragments.

java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1262 E/AndroidRuntime: at io.realm.RealmQuery$3.call(RealmQuery.java:1491) E/AndroidRuntime: at io.realm.RealmQuery$3.call(RealmQuery.java:1467) E/AndroidRuntime: at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) E/AndroidRuntime: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:137) E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) E/AndroidRuntime: at java.lang.Thread.run(Thread.java:856) E/AndroidRuntime: Caused by: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1262 E/AndroidRuntime: at io.realm.internal.TableQuery.nativeFindAllSortedWithHandover(Native Method) E/AndroidRuntime: at io.realm.internal.TableQuery.findAllSortedWithHandover(TableQuery.java:490) E/AndroidRuntime: at io.realm.RealmQuery$3.call(RealmQuery.java:1480) E/AndroidRuntime: at io.realm.RealmQuery$3.call(RealmQuery.java:1467)  E/AndroidRuntime: at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)  E/AndroidRuntime: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)  E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:137)  E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)  E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)  E/AndroidRuntime: at java.lang.Thread.run(Thread.java:856)

By the way, sometimes my during fast transactions between fragments my app crashes with SIGSEV or just completely freezes without throwing ANR, dunno if it's connected to the BadVersion, but just in case.

T-Bug

Most helpful comment

@ppamorim when https://github.com/realm/realm-java/pull/3834 is merged, this issue will probably be fixed along with it

All 47 comments

Hello, @Kistamushken

If the the specific version of the async query is not equal to the read lock's version, you can encounter BadVersionException. Is there removeChangeListener() or removeChangeListeners() in onStop() method? I think it has relevance to your problem.

@dalinaum Yeah, I do have removeChangeListener() in the onStop() method, I also tried removeChangeListener(listener) but it didn't really helped. Btw, can It be relative to the SIGSEV I get from time to time, I mean this thing with RealmChangeListener?

seems related to #2027

We have discovered a bug in how we handle queries across threads. This is currently being fixed by: https://github.com/realm/realm-core/pull/1405

We have just released 0.87.4 with a potential fix for this. We still haven't been able to reproduce the exact error you are reporting here, but upon investigation found something that appeared to be the root cause. So if you can test with 0.87.4 that would be much appreciated.

Seems fixed according to #2027

I have similar error on version 0.87.4:

java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1094
at io.realm.RealmQuery$5.call(RealmQuery.java:1847)
at io.realm.RealmQuery$5.call(RealmQuery.java:1817)
at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

Caused by: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1094
at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method)
at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:438)
at io.realm.RealmQuery$5.call(RealmQuery.java:1829)
at io.realm.RealmQuery$5.call(RealmQuery.java:1817) 
at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:818) 

Occurs randomly on app launch when it performs background network operations with writing results to Realm. On foreground activity I have listeners to Realm updates.

I'm using Realm v0.87.4 and have a similar crash.

Fatal Exception: java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1274
   at io.realm.RealmQuery$4.call(RealmQuery.java:1667)
   at io.realm.RealmQuery$4.call(RealmQuery.java:1642)
   at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
   at java.util.concurrent.FutureTask.run(FutureTask.java:234)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
   at java.lang.Thread.run(Thread.java:841)
Caused by io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1274
   at io.realm.internal.TableQuery.nativeFindAllMultiSortedWithHandover(TableQuery.java)
   at io.realm.internal.TableQuery.findAllMultiSortedWithHandover(TableQuery.java:498)
   at io.realm.RealmQuery$4.call(RealmQuery.java:1655)
   at io.realm.RealmQuery$4.call(RealmQuery.java:1642)
   at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
   at java.util.concurrent.FutureTask.run(FutureTask.java:234)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
   at java.lang.Thread.run(Thread.java:841)

Hey, im having this issue too. Im using realm: 0.87.5. And this is the stacktrace that fabric got to me.

Crashlytics - Crash - Bad Version

I'm using Realm v0.87.5, this exception still happening with same stack trace.

Any tip to not break the app if this issue happen? like a try catch or something...

Hi @heitorpr Unfortunately not. Right now the only work-around is using findAll instead of findAllAsync. A fix is being merged as we speak however: #2397

I see... Thanks =).

Hi Realm team.
We've updated Realm v0.88.0 and still have a BadVersionException problem.

Exception log from fabric is a little different from v0.87.5.
I attached it for your information.

Fatal Exception: java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1274
   at io.realm.RealmQuery$4.call(RealmQuery.java:1776)
   at io.realm.RealmQuery$4.call(RealmQuery.java:1751)
   at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:841)
Caused by io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1274
   at io.realm.internal.TableQuery.nativeFindAllMultiSortedWithHandover(TableQuery.java)
   at io.realm.internal.TableQuery.findAllMultiSortedWithHandover(TableQuery.java:502)
   at io.realm.RealmQuery$4.call(RealmQuery.java:1764)
   at io.realm.RealmQuery$4.call(RealmQuery.java:1751)
   at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:841)

Hi @hohnamkung
Yes, sorry for the trouble. We have finally been able to reproduce this and located the root cause. We hope to have a fix in 0.88.1: https://github.com/realm/realm-java/pull/2426

Wow. I'm really looking forward to v0.88.1.
Could you tell me when v0.88.1 is expected to be released?
This exception is quite urgent for us. Nearly 1K ~ 2K users have this exception in everyday.

We plan to release it today

:D. Thx!!! Looking foward to this!! :D
Em 14 de mar de 2016 7:51 AM, "Christian Melchior" [email protected]
escreveu:

We plan to release it today

—
Reply to this email directly or view it on GitHub
https://github.com/realm/realm-java/issues/2021#issuecomment-196254301.

@hohnamkung @heitorpr
Due to the complexity of this, it unfortunately won't make it into 0.88.1 after all, but there will be a 0.88.2 within the next couple of days with a fix for this. Sorry for the trouble this is causing.

Ook! Thx!
Em 14 de mar de 2016 10:16 AM, "Christian Melchior" <
[email protected]> escreveu:

@hohnamkung https://github.com/hohnamkung @heitorpr
https://github.com/heitorpr
Due to the complexity of this, it unfortunately won't make it into 0.88.1
after all, but there will be a 0.88.2 within the next couple of days with a
fix for this. Sorry for the trouble this is causing.

—
Reply to this email directly or view it on GitHub
https://github.com/realm/realm-java/issues/2021#issuecomment-196306218.

@heitorpr @hohnamkung 0.88.2 has been released with a fix for this.

=D. Thank you!!!!

2016-03-15 16:59 GMT-03:00 Christian Melchior [email protected]:

Closed #2021 https://github.com/realm/realm-java/issues/2021.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/realm/realm-java/issues/2021#event-590861107

Problem still occurs in version 0.88.3 on low end devices like LG L4 E440

04-18 09:42:34.133: E/AndroidRuntime(10716): FATAL EXCEPTION: main
04-18 09:42:34.133: E/AndroidRuntime(10716): java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1099
04-18 09:42:34.133: E/AndroidRuntime(10716): at io.realm.RealmQuery$5.call(RealmQuery.java:1974)
04-18 09:42:34.133: E/AndroidRuntime(10716): at io.realm.RealmQuery$5.call(RealmQuery.java:1944)
04-18 09:42:34.133: E/AndroidRuntime(10716): at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
04-18 09:42:34.133: E/AndroidRuntime(10716): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-18 09:42:34.133: E/AndroidRuntime(10716): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-18 09:42:34.133: E/AndroidRuntime(10716): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-18 09:42:34.133: E/AndroidRuntime(10716): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-18 09:42:34.133: E/AndroidRuntime(10716): at java.lang.Thread.run(Thread.java:856)
04-18 09:42:34.133: E/AndroidRuntime(10716): Caused by: io.realm.internal.async.BadVersionException: std::exception in io_realm_internal_TableQuery.cpp line 1099
04-18 09:42:34.133: E/AndroidRuntime(10716): at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method)
04-18 09:42:34.133: E/AndroidRuntime(10716): at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:443)
04-18 09:42:34.133: E/AndroidRuntime(10716): at io.realm.RealmQuery$5.call(RealmQuery.java:1956)
04-18 09:42:34.133: E/AndroidRuntime(10716): ... 7 more

Hi @dbacinski
Thanks, we will look into it.

Hi @dbacinski
We released 0.90 which fixed a few corner cases around this. Is it something you can verify or are you only seeing this crash through Crashlytics or similar?

We were able to reproduce this issue on our devices.

There were breaking changes in 0.90, so we need to do some work in order to upgrade. I will let you know when we will retest it.

@dbacinski Did you have a chance to upgrade and rerun your tests?

@dbacinski We haven't heard from you in 9 days so I'm closing this issue. Please let us know if it needs to be reopened!

Hi @cmelchior @kneth @emanuelez
I was able to reproduced this bug on 2.0.2
Occurs randomly on opening my app.
I don't know if it is important but in the app I'm using findAllAsync()/findFirstAsync() with asObservable() for querying database.

11-14 12:19:14.507 E: jni: ThrowingException 7, std::exception in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1131, .
11-14 12:19:14.526 E: io.realm.internal.async.BadVersionException: std::exception in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1131
 at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method)
 at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:446)
 at io.realm.RealmQuery$5.call(RealmQuery.java:2124)
 at io.realm.RealmQuery$5.call(RealmQuery.java:2115)
 at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
 at java.util.concurrent.FutureTask.run(FutureTask.java:237)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
 at java.lang.Thread.run(Thread.java:761)
11-14 12:19:14.583 E: FATAL EXCEPTION: main
  Process: com.my.app, PID: 1540
  java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1131
      at io.realm.AndroidNotifier.throwBackgroundException(AndroidNotifier.java:139)
      at io.realm.RealmQuery.closeSharedRealmAndSendEventToNotifier(RealmQuery.java:2201)
      at io.realm.RealmQuery.access$000(RealmQuery.java:62)
      at io.realm.RealmQuery$5.call(RealmQuery.java:2141)
      at io.realm.RealmQuery$5.call(RealmQuery.java:2115)
      at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
      at java.lang.Thread.run(Thread.java:761)
   Caused by: io.realm.internal.async.BadVersionException: std::exception in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1131
      at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method)
      at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:446)
      at io.realm.RealmQuery$5.call(RealmQuery.java:2124)
      at io.realm.RealmQuery$5.call(RealmQuery.java:2115) 
      at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) 
      at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
      at java.lang.Thread.run(Thread.java:761)

Hi @cmelchior @kneth @emanuelez
Happening on 2.2.2. This problem appears randomly.
Using Kotlin 1.0.4, LG G2 @ 6.0.1

E: jni: ThrowingException 7, std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130, .
E: Exception has been throw: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130
E: jni: ThrowingException 7, std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1284, .
E: Exception has been throw: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1284
E: io.realm.internal.async.BadVersionException: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130
       at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method)
       at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:436)
       at io.realm.RealmQuery$5.call(RealmQuery.java:2124)
       at io.realm.RealmQuery$5.call(RealmQuery.java:2115)
       at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)
D: Shutting down VM
E: FATAL EXCEPTION: main
   Process: com.tpro.dictate, PID: 22079
   Theme: themes:{default=overlay:com.brit.swiftdark, fontPkg:com.brit.swiftdark, com.android.systemui=overlay:com.brit.swiftdark, com.android.systemui.navbar=overlay:com.brit.swiftdark}
   java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130
       at io.realm.AndroidNotifier.throwBackgroundException(AndroidNotifier.java:138)
       at io.realm.RealmQuery.closeSharedRealmAndSendEventToNotifier(RealmQuery.java:2201)
       at io.realm.RealmQuery.access$000(RealmQuery.java:62)
       at io.realm.RealmQuery$5.call(RealmQuery.java:2141)
       at io.realm.RealmQuery$5.call(RealmQuery.java:2115)
       at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)
    Caused by: io.realm.internal.async.BadVersionException: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130
       at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method)
       at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:436)
       at io.realm.RealmQuery$5.call(RealmQuery.java:2124)
       at io.realm.RealmQuery$5.call(RealmQuery.java:2115) 
       at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) 
       at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
       at java.lang.Thread.run(Thread.java:818) 

@ppamorim when https://github.com/realm/realm-java/pull/3834 is merged, this issue will probably be fixed along with it

Please, I beg you to do this.

@ppamorim in the meantime, I think a possible solution would be to use findAll instead of findAllAsync and etc. But the pull request I mentioned seems scheduled for 2.4.0.

@Zhuinden I will be fired :D

Okay that's not fun, what is your deadline?

But seriously, if you replace all async query method with sync query methods, then this can be fixed temporarily.

Today, I can't do this change... But I can use a snapshot of the fixed version, what do you think?

The object store results integration is not merged yet.

@Zhuinden Solved?

Happening on 2.2.2. The problem happened because I use the method of findFirstAsync after deleting caches of my app.

06-13 16:33:44.145 15438-15835/? E/REALM_JAVA: io.realm.internal.async.BadVersionException: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130 at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method) at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:436) at io.realm.RealmQuery$5.call(RealmQuery.java:2124) at io.realm.RealmQuery$5.call(RealmQuery.java:2115) at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) 06-13 16:33:44.170 15438-15468/? E/CrashlyticsCore: Tried to write a fatal exception while no session was open. 06-13 16:33:44.185 15438-15438/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.zhihu.android.alpha, PID: 15438 java.lang.Error: io.realm.internal.async.BadVersionException: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130 at io.realm.AndroidNotifier.throwBackgroundException(AndroidNotifier.java:138) at io.realm.RealmQuery.closeSharedRealmAndSendEventToNotifier(RealmQuery.java:2201) at io.realm.RealmQuery.access$000(RealmQuery.java:62) at io.realm.RealmQuery$5.call(RealmQuery.java:2141) at io.realm.RealmQuery$5.call(RealmQuery.java:2115) at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) Caused by: io.realm.internal.async.BadVersionException: std::exception in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp line 1130 at io.realm.internal.TableQuery.nativeFindWithHandover(Native Method) at io.realm.internal.TableQuery.findWithHandover(TableQuery.java:436) at io.realm.RealmQuery$5.call(RealmQuery.java:2124) at io.realm.RealmQuery$5.call(RealmQuery.java:2115)  at io.realm.internal.async.BgPriorityCallable.call(BgPriorityCallable.java:36)  at java.util.concurrent.FutureTask.run(FutureTask.java:237)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)  at java.lang.Thread.run(Thread.java:761) 

@ppamorim @wenmagi We have some fundamental changes for async queries when we introduce the fine grained notifications. This issue should be fixed in the latest version. Please update the Realm to the latest version.

Agreed, Realm 2.x notifications with async queries had oddities, Realm 3.1.4 or Realm 3.3.x+ are much better choice

This issue still happens to my app on user devices

Caused by io.realm.internal.async.BadVersionException: std::exception in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 152
       at io.realm.internal.OsResults.nativeSize(OsResults.java)
       at io.realm.internal.OsResults.size + 367(OsResults.java:367)
       at io.realm.OrderedRealmCollectionImpl.size + 341(OrderedRealmCollectionImpl.java:341)
       at io.realm.RealmResults.size + 72(RealmResults.java:72)
       at mypackage.util.UDHelper.getUDs + 84(UDHelper.java:84)

UDHelper has following code:

        final RealmResults<SDocs> registeredDocs = sMainUIRealmInstance.where(SDocs.class).findAll();
        int registeredDocsCount = registeredDocs.size(); // this is line 84 where crash happens

previously it was just check registeredDocs.isEmpty() with absolutely the same crash so I tried to use registeredDocs.size() but no luck. I realize isEmpty() most probably utilizes the same size() method.
Realm is declared in gradle.build as classpath "io.realm:realm-gradle-plugin:5.9.1".

This generally shouldn't happen, but what happens if you put refresh() above it?

This generally shouldn't happen, but what happens if you put refresh() above it?

hi. i'm have same issue at isEmpty() and size()
refresh() not helping me)
i'm using realm 6.0.0

    io.realm.internal.async.BadVersionException: std::exception in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 152
        at io.realm.internal.OsResults.nativeSize(Native Method)
        at io.realm.internal.OsResults.size(OsResults.java:371)
        at io.realm.OrderedRealmCollectionImpl.size(OrderedRealmCollectionImpl.java:341)
        at io.realm.RealmResults.size(RealmResults.java:68)

@alexneo2003 Is it something you can reproduce?

@cmelchior i'm running Espresso test on my corporate app.
at first starting app in background downloading many static data. like schedule of working time, news by company and etc. and all this data writing in realm database.
at first run in test i'm cleaning app data and run it. and it run background operations with downloading/writing data.
at end of first testing app stoped and runing new test with run new app activity. and app create new instances for downloading/writing data.
but background data after first running still in progress and at this place my app is crashed with same error

in the code, the application checks if the results are not empty then process it with the next step

final RealmResults documents = realm
        .where(StatusDocuments.class)
        .equalTo("isArchive", false)
        .greaterThan("deliveryDate", 0)
        .lessThanOrEqualTo("deliveryDate", archiveDate)
        .findAll();

if (!documents.isEmpty()) {  <<---- crash at this point
    // do something
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wezley98 picture wezley98  Â·  3Comments

mithrann picture mithrann  Â·  3Comments

aschrijver picture aschrijver  Â·  3Comments

Merlin1993 picture Merlin1993  Â·  3Comments

CNyezi picture CNyezi  Â·  3Comments