realm-java: Realm does not support Kotlin ByteArray type (java byte[])

Goal

use ByteArray ( kotlin’s byte[] alias) with Realm

example: open class TestModel( @RealmField(name = "test") var test: ByteArray? = ByteArray(0)): RealmObject()

Expected Results

compiles fine

Actual Results

error: Field "test" of type "(@org.jetbrains.annotations.Nullable :: byte)[]" is not supported.

Code Sample

kotlin version which does not compile:
open class TestModel(
        @RealmField(name = "test")
        var test: ByteArray? = ByteArray(0)): RealmObject()`


java version which compile fine:
public class TestModel extends RealmObject {
    @RealmField(name = "test")
    public byte[] test;
}

Version of Realm and tooling

Realm version(s): ?=5.5.0

Realm sync feature enabled: no

Android Studio version: 3.2

Which Android version and device: emulator 8.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

I had the same error after updating some library versions. These two caused it:

  • updating com.bluelinelabs:conductor & support from 2.1.4 to 2.1.5
  • or updating com.jakewharton.timber:timber:4.5.1 to 4.7.1

I tried with realm 4.1.1 and 5.8.0, but it didn’t help. conductor and timber were the problems for me. I assume this behavior is a bug in annotation processing from some other library or plugin, so your solution might be different than mine, but I suggest you check whether you updated any libraries.

I’ve got this after adding Timber 4.7.1 to the project This is the log:

Equipment.java:18: error: Field "workCenterCode" of type "(@org.jetbrains.annotations.Nullable :: java.lang.String)" is not supported.

I’ve done little research and: Constants.JAVA_TO_REALM_TYPES has “byte[]” (string) as Type. Then it’s used to check supported field types in RealmProxyClassGenerator.emitPersistedFieldAccessors where field.asType().toString()= fieldTypeCanonicalName should be byte[] but it is (@org.jetbrains.annotations.NotNull :: byte)[]

I solved my problem by creating a small Java class that contained the byte array. It avoids the annotation. Thanks!