quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.64k forks source link

Quarkus + Jackson + inline reified = quarkus live reload broken with "Cannot inline bytecode built with JVM target 17" #37183

Open olivierbeltrandocintoo opened 10 months ago

olivierbeltrandocintoo commented 10 months ago

Describe the bug

Hello,

It seems that changing code using Quarkus + Kotlin + Jackson breaks compilation in quarkus live reload.

I have created a repo with a README.md containing the 4 the steps to reproduce

https://github.com/olivierbeltrandocintoo/quarkus-kotlin-bug-reload

This repo is

Expected behavior

Editing code should not break the live reload compilation

Actual behavior

The live reload shows the following stack trace Reason: Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option

Full stack trace below.

Error restarting Quarkus
io.vertx.core.impl.NoStackTraceException:

The stacktrace below has been reversed to show the root cause first. [Click Here](http://localhost:8080/user) to see the original stacktrace

java.lang.RuntimeException: Compilation failed.         val user : User = json.fromJson()
/home/olivier/dev/3p/rest-kotlin-quickstart2/src/main/kotlin/org/acme/GreetingResource.kt:19:32
Reason: Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option
    at io.quarkus.kotlin.deployment.KotlinCompilationProvider.compile(KotlinCompilationProvider.java:101)
    at io.quarkus.deployment.dev.QuarkusCompiler.compile(QuarkusCompiler.java:228)
    at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.checkForChangedClasses(RuntimeUpdatesProcessor.java:725)
    at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.doScan(RuntimeUpdatesProcessor.java:461)
    at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.doScan(RuntimeUpdatesProcessor.java:441)
    at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$5.call(VertxHttpHotReplacementSetup.java:150)
    at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$5.call(VertxHttpHotReplacementSetup.java:137)
    at io.vertx.core.impl.ContextBase.lambda$executeBlocking$0(ContextBase.java:167)
    at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:277)
    at io.vertx.core.impl.ContextBase.lambda$internalExecuteBlocking$2(ContextBase.java:199)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
    at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
    at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:833)
Resulted in: io.vertx.core.impl.NoStackTraceException

I don't know why it is obsessed with JVM 1.8 as no properties in the project use JVM 1.8.

Please note that changing the dependency from

    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
    </dependency>

(which is embedded in default kotlin project generated by quarkus) to

     <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
    </dependency>

makes no difference

How to Reproduce?

Go there: https://github.com/olivierbeltrandocintoo/quarkus-kotlin-bug-reload and git clone it

  1. start the app with mvn clean quarkus:dev
  2. visit http://localhost:8080/user with your browser, it should work :blush:

screen1

  1. edit the code by commenting something harmless (like the println) in the GreetingResource.kt

screen2

  1. visit http://localhost:8080/user again with your browser, it should crash :confused:

screen3

  1. Edit the JsonModule.kt with something harmless (like adding a new line), it should work again :open_mouth:

screen4

screen1

Output of uname -a or ver

Linux PARIS 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk 17 2021-09-14

Quarkus version or git rev

3.5.2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.3

Additional information

No response

quarkus-bot[bot] commented 10 months ago

/cc @evanchooly (kotlin), @geoand (jackson,kotlin), @gsmet (jackson)

olivierbeltrando commented 10 months ago

And from my personal computer I can reproduce the bug on linux (Ubuntu 22.04)

geoand commented 10 months ago

This would require a deep dive into what the Kotlin compiler produces

olivierbeltrandocintoo commented 10 months ago

really not sure how it works :/ I am assuming that a first step would be to figure out, what is the input of the Kotlin compiler. With that if we can reproduce the bug outside of Quarkus we probably can dispatch the issue to the Kotlin board if the bug is on their side. I unfortunately have no idea on how to do any of that :( (and I assume (maybe wrongly) that it would not imply diving in the Kotlin compiler (I hope))

mschorsch commented 10 months ago

Intellij can show you what the kotlin compiler produces in a human readable form.

  1. Tools > Kotlin > Show Kotlin Bytecode
  2. Button Decompile
geoand commented 10 months ago

I am well aware, thanks :)

olivierbeltrandocintoo commented 10 months ago

@mschorsch reproducing the issue (ie. commenting the println) -> from the generated code perspective the only change is image This does not look strange

mschorsch commented 10 months ago

@olivierbeltrandocintoo @geoand In my opinion this is a bug in the quarkus-maven-plugin because it seems that the kotlin compiler options did not get passed correctly to the plugin.

You can add the following snippet to your quarkus-maven-plugin configuration to work around the problem (https://quarkus.io/guides/kotlin#configuring-live-reload-compiler):

    <configuration>
        <compilerOptions>
            <compiler>
                <name>kotlin</name>
                <args>
                    <arg>-jvm-target=17</arg>
                </args>
            </compiler>
        </compilerOptions>
    </configuration>

Full example:

<plugin>
    <groupId>${quarkus.platform.group-id}</groupId>
    <artifactId>quarkus-maven-plugin</artifactId>
    <version>${quarkus.platform.version}</version>
    <extensions>true</extensions>
    <configuration>
        <compilerOptions>
            <compiler>
                <name>kotlin</name>
                <args>
                    <arg>-jvm-target=17</arg>
                </args>
            </compiler>
        </compilerOptions>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>build</goal>
                <goal>generate-code</goal>
                <goal>generate-code-tests</goal>
            </goals>
        </execution>
    </executions>
</plugin>
olivierbeltrandocintoo commented 10 months ago

testing immediately :)

olivierbeltrandocintoo commented 10 months ago

@mschorsch wow ! The provided workaround works well ! Thanks a lot :) Also I am a bit ashamed that I haven't read that section from the documentation 😅 although I have tried other things.

geoand commented 10 months ago

@mschorsch very good catch!