Skip to content
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

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

Closed
Postremus opened this issue Mar 26, 2021 · 3 comments · Fixed by #16048
Closed

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

Postremus opened this issue Mar 26, 2021 · 3 comments · Fixed by #16048
Assignees
Labels
area/devmode env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@Postremus
Copy link
Member

Postremus commented Mar 26, 2021

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"

@Postremus Postremus added the kind/bug Something isn't working label Mar 26, 2021
@quarkus-bot quarkus-bot bot added the env/windows Impacts Windows machines label Mar 26, 2021
@glefloch
Copy link
Member

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

@mkouba
Copy link
Contributor

mkouba commented Mar 26, 2021

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
Copy link
Contributor

mkouba commented Mar 26, 2021

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.

@mkouba mkouba self-assigned this Mar 26, 2021
mkouba added a commit to mkouba/quarkus that referenced this issue Mar 26, 2021
- always compare the number of methods
- resolves quarkusio#16047
@quarkus-bot quarkus-bot bot added this to the 1.14 - main milestone Mar 28, 2021
@gsmet gsmet modified the milestones: 1.14 - main, 1.13.1.Final Apr 3, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Apr 3, 2021
- always compare the number of methods
- resolves quarkusio#16047

(cherry picked from commit f89bf8e)
juazugas pushed a commit to juazugas/quarkus that referenced this issue Sep 30, 2021
- always compare the number of methods
- resolves quarkusio#16047
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devmode env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants