realm-java: Failure when computing UTF-16 size error_code = 1

Running:

  • Realm 3.5.0
  • Android 5.0.2

No Encryption All communication with Realm is performed with AsyncTasks.

Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       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.exceptions.RealmError: Unrecoverable error. Failure when computing UTF-16 size error_code = 5; retcode = 6; StringData.size = 2442; StringData.data =  in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_UncheckedRow.cpp line 151
       at io.realm.internal.UncheckedRow.nativeGetString(UncheckedRow.java)
       at io.realm.internal.UncheckedRow.getString(UncheckedRow.java:167)
       at io.realm.KeyValueObjectRealmProxy.realmGet$value(KeyValueObjectRealmProxy.java:116)
       at com.app.Cache.KeyValueObject.getValue(KeyValueObject.java:26)
       at com.app.Account.Account.loadArray(Account.java:192)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

I have this same (or similar) issue on Realm 6.1.0. I use an encrypted Realm db.

One user reported the app crashing, but after cleaning app data, the issue is solved. This supports the hypothesis that the Realm file(s) are somehow corrupted.

All the 15 crash logs of this single user show the following pattern:

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Failure when computing UTF-16 size error_code = $1; retcode = $2; StringData.size = $3; StringData.data = $4 in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_UncheckedRow.cpp line 161

In the above crash line, I’ve put numbered variables, which have the follwing values:

  • $1: all have value 1, except one has value 5.
  • $2: varies for some crashes, I’m not sure if there’s a pattern.
  • $3: in the range 600617.
  • $4: all values start with a URL (https://…somethingsomething) but end with AAAA. One ends with AAAAF. That’s possibly where some decoding breaks, maybe? One doesn’t end with AAAA or AAAAF, but the URL suddenly stops halfway and I see a bunch of user-written text directly appended to the URL (this is the one with $1 = 5). This looks like either a middle part of the string is missing, or some other string field got appended suddenly.

This particular user uses:

  • Realm 6.1.0
  • Android 9
  • Samsung Galaxy J5 with over 500 MB free RAM and over 4 GB free disk space

@bmunkholm Yes, sure, we can use special version.

Hi @trr-amsiq

Thanks. It seems to affect 2 users repeatedly, which suggests that their data is indeed faulty somehow and isn’t caused by a bug when reading the data. This was e.g. the case for similar errors we saw using encryption where we had a race condition that caused wrong data to be read from disk.

If the underlying data is indeed corrupted, it begs the question on how that happened. It could be a bug in Realm, the OS or disk corruption happening after the data was written.

I don’t want to be pessimistic, but without any further to go on, we will probably not be able to solve this as historically it is a huge time sink to investigate these kinds of issues, and the chance of actually finding anything is extremely low unless we can reproduce the error.

I’ll keep this issue open though as we definitely want to be able to track if others are seeing similar things.

Just to preserve history:

  • Error happened to two users repeatedly
  • SM-J110F (Android 4.4.4)
  • SM-G530H (Android 5.0.2)