https://kotlinlang.org logo
#announcements
Title
# announcements
k

Kris-Gerhard Aabrams

08/07/2020, 6:46 AM
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

LeoColman

08/07/2020, 2:43 PM
@sam
Seems to be because the native image isn't able to do use reflections without configuration for specific reflections
s

sam

08/07/2020, 3:00 PM
Yeah it's a not a multiplatform library, it requires extension use of reflection
k

Kris-Gerhard Aabrams

08/07/2020, 3:21 PM
I've no idea which reflection config is missing though.
s

sam

08/07/2020, 3:22 PM
I don't know anything about kotlin native so don't know what level of reflection is available
k

Kris-Gerhard Aabrams

08/07/2020, 3:22 PM
To be clear, i'm using Quarkus and GraalVM's native image in the project not Kotlin Native.
s

sam

08/07/2020, 3:23 PM
I see.
And "Only instances of KClass are supported" sometimes gets thrown ?
I wonder if it's to do with nested classes
k

Kris-Gerhard Aabrams

08/07/2020, 3:24 PM
Yes. I've narrowed down the classes that is does this check on.
l

LeoColman

08/07/2020, 3:24 PM
KClass is a reflective access to a specific class of yours
You should probably add both to graal configs
k

Kris-Gerhard Aabrams

08/07/2020, 3:24 PM
It's two classes which i created, and i've added the @RegisterForReflection annotation for them. AND two kotlin classes "String" and "Long".
l

LeoColman

08/07/2020, 3:24 PM
But I'm not exactly sure about how that works
k

Kris-Gerhard Aabrams

08/07/2020, 3:25 PM
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

sam

08/07/2020, 3:26 PM
Try adding
Copy code
KClassifier
k

Kris-Gerhard Aabrams

08/07/2020, 3:28 PM
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

sam

08/07/2020, 3:40 PM
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

Kris-Gerhard Aabrams

08/07/2020, 3:45 PM
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

sam

08/07/2020, 3:47 PM
Right
It might help if the error included the class then
k

Kris-Gerhard Aabrams

08/07/2020, 3:48 PM
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

LeoColman

08/07/2020, 3:51 PM
Try to investigate a little bit into require source code
Maybe it's losing the right reflection somewhere?
Doesn't seem likely tho
s

sam

08/07/2020, 3:56 PM
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

Kris-Gerhard Aabrams

08/07/2020, 3:57 PM
Tnx guys!! 🎉
s

sam

08/07/2020, 4:01 PM
@Kris-Gerhard Aabrams I will ping you in #hoplite when the release is ready
k

Kris-Gerhard Aabrams

08/17/2020, 8:28 PM
Only instances of KClass are supported [was null]
Didn't help me much 😄 Some mysterious reflection is still missing 🙂
😂 1
s

sam

08/24/2020, 2:02 PM
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

Kris-Gerhard Aabrams

08/25/2020, 8:58 AM
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
4 Views