-
Notifications
You must be signed in to change notification settings - Fork 8
[dev/kotlin-support] Weird issue decoding structs that have enum properties #8
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi, Probably this happened because of a lack of information about your package in JavaCoder. Please check an example of this override in swift-java-codegen. We are looking for a mechanism to resolve this issue in compile-time but for now we recommend to put all SwiftValue in one package and use those overrides A general recommendation for issues like that: try to reproduce it in swift-java-codegen. If the issue reproduced we will really appreciate it if you create a PR with a failing test for this particular issue |
I believe we have the package set appropriately because the
I'll reproduce it in swift-java-codegen and create a PR with a failing test. Thanks @andriydruk! |
@andriydruk I finally figured out was breaking string-backed enums for us. I did turn out to be the package name like you thought. It was super subtle:
vs
🤦 |
Given a swift struct that contains an enum-typed property (see below), its kotlin
@SwiftValue
-annotated counterparts, a single instance bridges perfectly back and forth over the bridge, via the JavaDecoder/JavaEncoder, with no loss in data. But when you have anArrayList
of instances of the kotlin data class that represents the swift struct, the value for the enum-typed property is lost and isnil
on the swift side. I've chased this issue all the way down through JavaDecoder to where it tries to get the Field ID for the java object for the enum type. It fails to find the Field ID and prints an error (it's just logged because the missing field strategy that gets generated by swift-java-codegen is always.ignored
) that saysIgnored error: fieldNotFoundException for ....
Here's an example. Consider a scenario where you have a Swift and their Kotlin counterparts like below:
Consider also their kotlin counterparts:
If I were to try to passing a
CarCollection
over the bridge from the kotlin side to the swift side,JavaDecoder
would eventually try to decode aCar
from the array list ofCar
s, and furthermore, eventually try to decode thecategory
field onCar
. This is where the problem shows up. The JNI bridging code tries to look up the FieldID for thecategory
field onCar
. However, when a type likeCar
that has a property that is an enum (maybe even just a string backed enum, not sure though), is in an array, the decoding process essentially fails to decode the whole object over the bridge because these properties that are enums end up failing to decode. If you were simply trying to decode a singularCar
, that wasn't in an array list, everything would work properly.I haven't been able to pin it down yet, but could there be a state issue with
JavaDecoder
when it createsJavaArrayContainer
and then aJavaObjectContainer
or is there something going on deeper in the JNI support code. Or could it be an issue with the bytecode generated by kotlin?Thanks in advance for looking into this.
cc: @zayass @andriydruk
The text was updated successfully, but these errors were encountered: