-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin reflection fails in native build in some cases that Java reflection success #8479
Comments
Can you paste the error you get please? |
The error is related to invalid state deep inside Kotlin's library. Here is the stack trace...
|
@geoand I just hit this. It's a known issue oracle/graal#2306. The workaround only partially worked for me, requiring tweak to resources.json. Probably needs a fix in
With the resources.json in place, Jackson started breaking with:
I have never seen the
Anyhow, with all these tweaks it works. Quarkus 1.5.2 and graal 20.1.0-java8 |
Thanks for the information @sherl0cks. I think we can probably make the current quarkus-kotlin extension register the info automatically, shouldn't be hard. @RotBolt would you perhaps like to take a look? |
Sounds good @geoand. I'd really love some more info on the MyClass[] syntax. What is the name of this syntax? Why does Graal need it? Why does it not work with kotlin and @RegisterForReflection? One of the strangest things I've seen in my graal/quarkus journey... |
I think it's just the array syntax written in a more readable form. |
@geoand will look into this 👍 |
This seems to be the info on syntax. Why it doesn't work in @registerForReflection is still a mystery to me: https://stackoverflow.com/questions/41207060/how-to-get-a-kclass-of-array |
A similar error occurs in Quarkus 1.6.0.CR1 when trying to serialize a built-in Kotlin List, e.g.
JVM-mode works fine but in native-mode (GraalVM 20.1) the following errors occurs:
|
Looks like something that would be addressed by #3954 (comment). @RotBolt do you want to take it? |
Just hit this again. Any progress on a fix? Anyway I can help? |
Same here, I'm also running into these kinds of troubles. Mainly writing this down for the next person to find some help. For me it mostly is connected to Jackson serialization together with the jackson-kotlin module. After manually registering a lot of array-valued classes (using This is what I needed to do to go past that @RegisterForReflection(
targets = [
kotlin.reflect.jvm.internal.ReflectionFactoryImpl::class,
KotlinVersion::class,
Array<KotlinVersion>::class,
KotlinVersion.Companion::class,
Array<KotlinVersion.Companion>::class,
]
)
class ReflectionRegistrator I additionally registered my own classes - although they were already marked with |
Okay, after some heavy debugging I could find out what was causing the issue in my case. It may sound weird, but this is how it goes: Everything works in the whole piece of software until I start using something that uses Kotlin coroutines under the hood. Then it all breaks, showing the symptoms you can see above. Even without manually registering the classes as I did in my previous post, it just works - until there is a single coroutine call somewhere in my application. This seems to be what #7999 states - I just was not realizing it, because it looked like something else. This is what I needed to change to fix my system. Removing: val elements = sequence<DbEvent?> { sendOne() }.filterNotNull() Instead writing val elements = listOf(sendOne()).filterNotNull() does not show the symptoms. I tried whether I need to actually call the code causing it, which does not seem to be the case. Having this: if (Math.random() > 2.0)
sequence<DbEvent?> { sendOne() }.filterNotNull() will make it fail as well. |
I am running into this issue with Quarkus 2.0.1 and the workaround suggested here doesn't seem to work. If I apply the configuration like this:
The application would fail on start:
If I pass the resources in the yaml file like this:
It would start but it would fail with the same error.
|
Any progress on a fix? I'm facing the same problem... |
Found the fix. just need to integrate it. |
fixes quarkusio#8479 (cherry picked from commit ad1e5d4)
Kotlin method references (e.g.
this::someMethod
) have a s nice shorthand for retrieving the reflectionjava.lang.reflect.Method
via thejavaMethod
property as inthis::someMethod.javaMethod
.When using a JAX-RS
UriInfo
to build location headers, using the reflected method reference is a great way to keep things DRY so as not to repeat path information stated in a@Path
annotation.For example:
Using Kotlin references is a great shorthand and keeps things type safe and compile type checked as compared to using Java...
In Kotlin
path(this::fetch.javaMethod)
In Java
As usual, all is well in JVM mode (and both examples work correctly) but in native mode the Kotlin version throws an error deep in the bowels of its reflection library.
Expected behavior
Kotlin's reflection tools work the same as equivalent Java reflection in both JVM and native builds.
Actual behavior
In native builds Kotlin reflection for method references fails.
To Reproduce
rest-kotlin-quickstart.zip
Environment (please complete the following information):
Output of
uname -a
orver
:Output of
java -version
:Quarkus version or git rev:
Build tool (ie. output of
mvnw --version
orgradlew --version
):The text was updated successfully, but these errors were encountered: