Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realm does not support Kotlin ByteArray type (java byte[]) #6153

Closed
filipkowicz opened this issue Sep 6, 2018 · 17 comments
Closed

Realm does not support Kotlin ByteArray type (java byte[]) #6153

filipkowicz opened this issue Sep 6, 2018 · 17 comments

Comments

@filipkowicz
Copy link

filipkowicz commented Sep 6, 2018

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

@Zhuinden
Copy link
Contributor

Zhuinden commented Sep 6, 2018

Have you tried ByteArray instead of ByteArray??

@filipkowicz
Copy link
Author

same thing:

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

): RealmObject()

gives java class:

@kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0012\n\u0002\b\u0005\b\u0016\u0018\u00002\u00020\u0001B\u000f\u0012\b\b\u0002\u0010\u0002\u001a\u00020\u0003\u00a2\u0006\u0002\u0010\u0004R\u001e\u0010\u0002\u001a\u00020\u00038\u0006@\u0006X\u0087\u000e\u00a2\u0006\u000e\n\u0000\u001a\u0004\b\u0005\u0010\u0006\"\u0004\b\u0007\u0010\u0004\u00a8\u0006\b"}, d2 = {"Lch/sherpany/boardroom/model/encryption/TestModel;", "Lio/realm/RealmObject;", "test", "", "([B)V", "getTest", "()[B", "setTest", "app_debug"})
public class TestModel extends io.realm.RealmObject {
    @org.jetbrains.annotations.NotNull()
    @io.realm.annotations.RealmField(name = "test")
    private byte[] test;
    
    @org.jetbrains.annotations.NotNull()
    public final byte[] getTest() {
        return null;
    }
    
    public final void setTest(@org.jetbrains.annotations.NotNull()
    byte[] p0) {
    }
    
    public TestModel(@org.jetbrains.annotations.NotNull()
    byte[] test) {
        super();
    }
    
    public TestModel() {
        super();
    }
}

I think that annotation @org.jetbrains.annotations.NotNull() could be a problem

@filipkowicz
Copy link
Author

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)[]

@cruxdyno
Copy link

cruxdyno commented Dec 13, 2018

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.

@Grohden
Copy link

Grohden commented Jan 2, 2019

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.

@Grohden
Copy link

Grohden commented Jan 2, 2019

Maybe this is related?
JakeWharton/timber#295

@Grohden
Copy link

Grohden commented Jan 2, 2019

Changing the nullable import from
import org.jetbrains.annotations.Nullable; to import android.support.annotation.Nullable;
Fixed the build for me. But i'm not sure what changes with this...

@edgar-zigis
Copy link

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.

Same here, issue appeared after updating Timber to 4.7.1

@zeroarst
Copy link

zeroarst commented Mar 27, 2020

Having the same issue with Timber 4.7.1...anyone found the solution..?

@phamquan
Copy link

phamquan commented Aug 8, 2020

It seems to be the only solution now is to downgrade Timber to 4.5.0

@jeromep01
Copy link

i can confirm that byte[] instead of nullable byte[] works

@VitalyKolchenko
Copy link

api("com.jakewharton.timber:timber:4.7.1") {
        exclude group: "org.jetbrains", module: "annotations"
    }

Does the thing

@paulelias
Copy link

Changing the nullable import from
import org.jetbrains.annotations.Nullable; to import android.support.annotation.Nullable;
Fixed the build for me. But i'm not sure what changes with this...

I'm new to Kotlin and Android. I'm trying to compile a project that uses Realm and there's a class that produces the same error about "@org.jetbrains.annotations.NotNull byte[] is not supported". I want to try replacing the jetbrains Nullable annotation with the android annotation but I can't figure out how to do that. It seems that no matter what I try, the class is always compiled with the jetbrains annotation and I get the error. I'm sure there's something basic I'm missing but I've spent several hours searching stack overflow and other sites without any luck. Can anyone point me in the right direction? Thanks!

@Grohden
Copy link

Grohden commented Nov 4, 2021

@paulelias it's probably imported somewhere else 🤔 I would search the entire project for it (if recall the shortcut in android studio for search everywhere is shift+shift, you can search for the import or review all nullable annotations in the project just to be sure)

Intellij/Android Studio also might have added it to build gradle (don't think that it does this.. but doesn't hurt to give a look), but since you said it gives this error in a class it might be cache... ./gradlew clean probably can solve in this case I think

@paulelias
Copy link

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

@ntoskrnl
Copy link

subprojects {
  configurations.all {
    resolutionStrategy.force 'org.jetbrains:annotations:13.0'
  }
}

also works

@sync-by-unito sync-by-unito bot closed this as completed Dec 15, 2021
@brucemax
Copy link

brucemax commented Sep 3, 2023

Just adding constraint layout library for compose to project breaks the build. What!?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests