quarkusio / quarkus

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

Hot Reload: class redefinition failed: attempted to delete a method #16047

Closed Postremus closed 3 years ago

Postremus commented 3 years ago

Describe the bug

I have the following class in my project:

public class GreetingResource {

    private static final String CONST = "4";

    public void help() {

    }
}

I changed the CONST and removed the help method at the same time. A hot reload triggered the exception from below.

Expected behavior

No exception during hot reload.

Actual behavior

2021-03-26 13:26:19,160 INFO  [io.qua.dep.dev.RuntimeUpdatesProcessor] (vert.x-worker-thread-15) Changed source files detected, recompiling [C:\workspaces\aviator\hot-reload-static-final\src\main\java\org\acme\GreetingResource.java]
2021-03-26 13:26:19,220 INFO  [io.qua.dep.dev.RuntimeUpdatesProcessor] (vert.x-worker-thread-15) Application restart not required, replacing classes via instrumentation
2021-03-26 13:26:19,221 ERROR [io.qua.dep.dev.RuntimeUpdatesProcessor] (vert.x-worker-thread-15) Failed to replace classes via instrumentation: java.lang.UnsupportedOperationException: class redefinition failed: attempted to delete a method
        at java.instrument/sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
        at java.instrument/sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:193)
        at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.doScan(RuntimeUpdatesProcessor.java:236)
        at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$2.handle(VertxHttpHotReplacementSetup.java:62)
        at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$2.handle(VertxHttpHotReplacementSetup.java:52)
        at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)

To Reproduce

Link to a small reproducer (preferably a Maven project if the issue is not Gradle-specific).

Or attach an archive containing the reproducer to the issue.

Steps to reproduce the behavior:

  1. Download the reproducer: hot-reload-static-final.zip
  2. mvn quarkus:dev
  3. In GreetingResource, change the value of CONST, and remove the "help()" Method.
  4. Go to http://localhost:8080/hello
  5. Exception from above happens

Environment (please complete the following information):

Output of uname -a or ver

MSYS_NT-10.0 NANB7NLNVP2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys

Output of java -version

java version "1.8.0_271" Java(TM) SE Runtime Environment (build 1.8.0_271-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)

Quarkus version or git rev

1.13.0.Final

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: C:\eclipse\tools\apache-maven\bin.. Java version: 11.0.7, vendor: Azul Systems, Inc., runtime: C:\eclipse\tools\zulu11.39.15-ca-jdk11.0.7-win_x64 Default locale: de_DE, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

glefloch commented 3 years ago

@mkouba could we catch the exception and restart if it happens?

mkouba commented 3 years ago

Well, first of all we should not attempt to use instrumentation for this case (the class structure was obviously modified). I'll check the reproducer.

mkouba commented 3 years ago

Ok, so I was able to reproduce the issue and (1) the comparison logic in ClassComparisonUtil.isSameStructure(ClassInfo, ClassInfo) needs to be fixed to reflect the method removal, (2) the exception is logged but the full restart is perfomed afterwards and the result of the subsequent GET http://localhost:8080/hello is correct.