I'm using a Kotlin specific library. Everything wo...
# announcements
k
I'm using a Kotlin specific library. Everything works in JVM mode but when running the app as native somewhy this check fails. https://github.com/sksamuel/hoplite/blob/master/hoplite-core/src/main/kotlin/com/sksamuel/hoplite/decoder/DecoderRegistry.kt#L44
l
@sam
Seems to be because the native image isn't able to do use reflections without configuration for specific reflections
s
Yeah it's a not a multiplatform library, it requires extension use of reflection
k
I've no idea which reflection config is missing though.
s
I don't know anything about kotlin native so don't know what level of reflection is available
k
To be clear, i'm using Quarkus and GraalVM's native image in the project not Kotlin Native.
s
I see.
And "Only instances of KClass are supported" sometimes gets thrown ?
I wonder if it's to do with nested classes
k
Yes. I've narrowed down the classes that is does this check on.
l
KClass is a reflective access to a specific class of yours
You should probably add both to graal configs
k
It's two classes which i created, and i've added the @RegisterForReflection annotation for them. AND two kotlin classes "String" and "Long".
l
But I'm not exactly sure about how that works
k
I've already added this snippet to the config
Copy code
{
    "name": "kotlin.reflect.jvm.internal.KClassImpl",
    "allPublicMethods": true,
    "allDeclaredFields": true,
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  },
  {
    "name": "kotlin.reflect.KClass",
    "allPublicMethods": true,
    "allDeclaredFields": true,
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  },
Something seems missing ๐Ÿ™‚
s
Try adding
Copy code
KClassifier
k
Build takes roughly 8 minutes. Let's see
I'm pretty sure i've already tried it though
At first a had the error that my class is not "data class" but i think this got resolved when i added the KClass to reflection config
s
I don't know how graal works, but this line that has the error:
require(type.classifier is KClass<*>) { "Only instances of KClass are supported" }
.classifier is the KClassifier
k
No luck unfortunately
Copy code
MyConfig::class.createType().classifier is KClass<*>`
Returns true by the way.
So the same thing either doesn't work in
require(type.classifier is KClass<*>) { "Only instances of KClass are supported" }
or the actual type that is there is not registered for reflection.
s
Right
It might help if the error included the class then
k
It would
I've invested way too many hours in this issue ๐Ÿ˜„ I'll come back to it next week. It's a good idea to make an adjustment to this error message (Y) it'd definitely help me debug later
l
Try to investigate a little bit into require source code
Maybe it's losing the right reflection somewhere?
Doesn't seem likely tho
s
I will update the error message and release another version. Then you can upgrade at your leisure and hopefully the problem will become clear.
k
Tnx guys!! ๐ŸŽ‰
s
@Kris-Gerhard Aabrams I will ping you in #hoplite when the release is ready
k
Only instances of KClass are supported [was null]
Didn't help me much ๐Ÿ˜„ Some mysterious reflection is still missing ๐Ÿ™‚
๐Ÿ˜‚ 1
s
Helps a bit ๐Ÿ™‚
Because we know that type.classifier is null
Copy code
/**
 * The declaration of the classifier used in this type.
 * For example, in the type `List<String>` the classifier would be the [KClass] instance for [List].
 *
 * Returns `null` if this type is not denotable in Kotlin, for example if it is an intersection type.
 */
@SinceKotlin("1.1")
public val classifier: KClassifier?
Sounds like a bug in kotlin tbh
k
Copy code
MyCustomConfigClass::class.createType().classifier
works by the way
It returns a not null value
I'll try to mimic the exact call path in couple of hours
Copy code
<http://log.info|log.info>("classifier: " + (Config::class.createType().classifier).toString()) <-- returns value
Config::class.constructors.first().parameters.map {
  <http://log.info|log.info>("constructor parameter type: " + (it.type).toString()) <-- returns value
  <http://log.info|log.info>("constructor parameter type classifier: " + (it.type.classifier).toString()) <-- returns null
}
Copy code
constructor parameter type: kotlin.String
constructor parameter type classifier: null