Trying to understand some strange behavior with th...
# kotlin-native
j
Trying to understand some strange behavior with the K/N compiler. I have a case where, as I’m trying to debug through a confusing crash, adding a line of
somePointer.rawValue
corrects the issue. I’m not using the value, just putting that line as a statement. Are there some side-effects anyone is aware of to calling
.rawValue
on a pointer (implemented as a getter of
value.toNativePtr()
internally) that might explain what I’m seeing? I have a number of other things to debug into, but seeing this leads me to believe there’s more going on here that I need to understand first.
k
Don’t know about the call. what’s the crash?
j
I think the root cause is something I’m doing wrong with JNI. Using it to call a Kotlin class in a JVM (strange use case, I realize), and getting a null result back from JNI (with no exception) where the method cannot return null.
This
.rawValue
call I alluded to above is in the implementation for another method which the JVM class calls via JNI on that side. It’s actually just a debug print message method used on both ends. I noticed that when I remove the call from the Kotlin/JVM source, this NPE situation happens. Introducing the call, even when the K/N implementation does nothing but take the
jstring
pointer and call
.rawValue
, causes everything to work properly. So something’s behaving strangely; I’m still hunting down stuff in the JNI bits I’m using, as I suspect it will end up being a GlobalRef vs LocalRef situation where the JVM has moved things out from under me. We’ll see.
👍 1
Follow-up: pretty sure I have the root cause addressed (it did end up being JNI GlobalRef shenanigans). Still a bit mystified why the call to
.rawValue
in K/N was fixing/masking the issues, but I at least have a path forward.