Android Java SDK: Wrong kind of table

Hi,

I bumped on a new issue today, while trying to write data to a Collection.
I’m working on an Android Project with Kotlin and Realm Sync since a few months, and the testing has been quite extensive on all the projects features.
I’m pretty sure this wasn’t happening a few months ago, wondering if it’s a new thing.

So the scenario is:

  • WorkOrder collection: items contain an optional reference to Asset collection

var productData: Asset? = Asset(),

  • Asset collection: it’s an embedded collection (@RealmClass(embedded = true)) with a reference to another embedded collection

var installedFirmware: InstalledFirmware? = InstalledFirmware()

When I try to write a new Asset on a WorkOrder, it throws an exception:

java.lang.IllegalStateException: Wrong kind of table
Exception backtrace:
backtrace not supported on this platform

I found out that if I change:

  • var installedFirmware: InstalledFirmware? = InstalledFirmware()

to

  • var installedFirmware: InstalledFirmware? = null

everything works just fine.
I tested the same in other objects as well.

What’s the logic behind this?
I can easily change to have null in those cases, but I’d like to understand why that’s needed.

Thanks,
Alessandro

Hello @Alessandro_Benvenuti1,

Welcome to the Community :smiley:

WorkOrder collection: items contain an optional reference to Asset collection

java.lang.IllegalStateException: Wrong kind of table
Exception backtrace:
backtrace not supported on this platform

Could you please share the full model definition that was before and after? Did you recently update the SDK version or made any changes that led to this error you getting?

What’s the logic behind this?
I can easily change to have null in those cases, but I’d like to understand why that’s needed.

This is dependent on the use-case of your application. Generally, both null and object references from an constructor should work.

I look forward to your response.

Cheers, :performing_arts:

Hi Henna :slight_smile:

Thanks for your reply.
Here my models:

open class WorkOrder(
@PrimaryKey var _id: ObjectId = ObjectId(),
@Required var _partition: String = “”,
var productData: Asset? = Asset()
) : RealmObject() {

@RealmClass(embedded = true)
open class Asset(
@Required var serialNumber: String = “”,
var installedFirmware: InstalledFirmware? = InstalledFirmware()
) : RealmObject()

@RealmClass(embedded = true)
open class InstalledFirmware (
@Required var supplier: String = “”,
@Required var model: String = “”,
@Required var version: String = “”
) : RealmObject()

(I’ve removed a bunch of properties from Asset and WorkOrder, to make it easier)
With this setup I still get that error on Client (android kotlin) side:

E/REALM_JNI: jni: ThrowingException 9, Wrong kind of table
Exception backtrace:
<backtrace not supported on this platform>, .
E/REALM_JNI: Exception has been thrown: Wrong kind of table
Exception backtrace:
<backtrace not supported on this platform>

On server side, on Logs, I can see the write attempt but no changes are actually written:

Logs:
[
“Upload message contained 1 changeset(s)”,
“Integrating upload required conflict resolution to be performed on 0 of the changesets”,
“Latest server version is now 300”,
“Number of upload attempts was 1”
]
Partition:
myPartition
Write Summary:
{
“WorkOrder”: {
“updated”: [
“longGeneratedId”
]
}
}
Remote IP Address:
..*.
SDK:
android v10.10.1
Platform Version:
11

If I change this line:

var installedFirmware: InstalledFirmware? = InstalledFirmware()

to

var installedFirmware: InstalledFirmware? = null,

everything works smoothly.

I don’t recall any change on SDK side nor on server side.
I can replicate the issue at any time apparently :slight_smile:

Thanks!
Alessandro

G’Day, @Alessandro_Benvenuti1,

Thank you for sharing the requested details.

It is possible to initialize an object reference with a directly constructed object if it has a no-arg constructor.
but Realm requires an empty constructor for its internal processing so, in the absence of a real no-arg constructor, it is causing the reflective lookup to fail and hence the error.

Could try to rework the InstalledFirmware to only have the default no-arg constructor and assign the defaults inside the class instead?

I look forward to your response.

Cheers, :performing_arts:

Hi Henna,

thank’s for the help and sorry for my (really) late reply!

It looks like that doesn’t fix the problem.
I have changed my code such as:

@RealmClass(embedded = true)
open class InstalledFirmware () : RealmObject() {
    @Required var supplier: String = ""
    @Required var model: String = ""
    @Required var version: String = ""
}

And same for the Asset class.
I get the same error when I try to write an Asset object to the db.

Furthermore I’ve just realised that I can have this in my WorkOrder class:

var productData: Asset? = Asset(),

but I can’t have this in my Asset class:

var installedFirmware: InstalledFirmware? = InstalledFirmware()

Both Asset and InstalledFirmware are flagged as @RealmClass(embedded = true), WorkOrder is not.

Cheers,
Alessandro

G’Day, @Alessandro_Benvenuti1 ,

Apologies for the delay in getting back to you. Were you able to go past this error?

I have raised this concern internally and will get back once I have feedback. It’s possible this may have to do with multiple levels of embedded classes but will get a confirmation on this soon.

Meanwhile, please feel free to share any more observations or feedback.

I genuinely appreciate your patience with us on this.

Cheers, :performing_arts: