vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

Add/Delete Method not implemented - Hot Code Replace

Open soccerdude288 opened this issue 3 years ago • 3 comments

My company works on a larger sized Java project, and we cannot get hot code replace to work in vscode. I suspect this is probably related to something about our specific project and how it's set up, and I'm hoping someone can give further direction for troubleshooting the problem.

Environment
  • Operating System:
    • Host: Ubuntu 22.04/21.10
    • Running App (Docker Images):
      • FROM ghcr.io/graalvm/graalvm-ce:java17-21.3.0
      • FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:18-bullseye (installing graal manually)
  • JDK version: 17 (graal, but also tested using open-jdk)
  • Visual Studio Code version: 1.69.2
  • Java extension version: 1.9.0 (Redhat)
  • Java Debugger extension version: 0.43.0
Steps To Reproduce

Due to the complex nature of our project, I'm not sure how to provide a reproducible example. Here are some things we've tried.

  • We run our java app in a container managed by kubernetes. We are able to attach the debugger to the running process, but hot code deploy will fail to work.
  • We've recently ported our app into a vscode dev container, attached to that local running process, and unsuccessfully done hot code deploy

We came from using NetBeans where this worked flawlessly, and just confirmed it still works. I've also confirmed Intelij can successfully do hot code deploy as well with our project.

Current Result

Our most simple test is adding a system.out to an existing method. No other changes. That produces the following stacktrace.

image

Other Information

We've reviewed the information at here and here with no luck.

soccerdude288 avatar Aug 03 '22 15:08 soccerdude288

@soccerdude288 thanks for reaching out. HCR failures may be related to different Java compilers. VS Code Java uses Eclipse Compiler for Java (ECJ) to compile your modified java code, but Java artifacts running in the container are compiled by the build tool, which mostly uses the JDK's built-in javac compiler. AFAIK, the classes generated by ECJ may have subtle differences from the javac compiler. When you apply a changed class generated by ECJ to a remote JVM, it may find that the method is not equivalent to the old method of javac and detect it as a new method.

Can you provide a minimal Java snippet so I can check if it is caused by a different compiler? The snippet does not need to be your actual product code, just a sample that reproduces the issue.

testforstephen avatar Aug 05 '22 02:08 testforstephen

Hi have the exact same issue.

I've the following launch configuration:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "Launch Java Program",
      "request": "launch",
      "mainClass": "org.test.Test",
      "args": "--spring.profiles.active=local"
    },
    {
      "type": "java",
      "name": "Attach to the Backend inside the container",
      "request": "attach",
      "hostName": "localhost",
      "port": "8099"
    }
  ]
}

When I run the "local" configuration, VSCode recompile everything and it the hot code replace works correctly.

Now if I'm running the java code inside a Docker container defined with this Dockerfile:

FROM openjdk:11-jre-slim as local

VOLUME /code
WORKDIR /code

ENTRYPOINT ["java","-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8099","-jar","backend.jar","--spring.profiles.active=local-docker"]

The code hot replace returns the following problem: Hot code replace failed - Add method not implemented. Would you like to restart the debug session?

With IntelliJ IDEA with the Docker setup I'm able to hot swap the code using the "Debug" -> "Debug Actions" -> "Reload Changed Classes".

massimeddu-boom avatar Aug 25 '22 16:08 massimeddu-boom

Even I am facing the same issue with Cloud Foundry docker

anandncode avatar Feb 13 '23 08:02 anandncode