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

final static variable values duplicates when hot swap #549

Open
UyCode opened this issue Apr 30, 2024 · 1 comment
Open

final static variable values duplicates when hot swap #549

UyCode opened this issue Apr 30, 2024 · 1 comment

Comments

@UyCode
Copy link

UyCode commented Apr 30, 2024

for example, if I have a:

public class Test {
  private final static List<String> test = new ArrayList<>();
  {
      test.add("1");
  }
  @GetMapping("/test")
  public List<String> getTestList() {
    return test;
  }
}

if add new item like test.add("2"); and let the agent hot swap, then I would get:
"1",
"1",
"2"

I think it because of the static, that agent not cleaned up before hot swap

@skybber
Copy link
Contributor

skybber commented Apr 30, 2024

ClassInitPlugin copies method and instruments it to initialize new static fields. Old static instances are not recreated, so in your case HA method adds additional values to test field. It is unsolvable to keep old static instance of test (it is kept by dcevm not HA) and apply only addition of items that are new in new variant of method. Another approach is to recreate instance after redefinition, but there is next problem with modifications out of method - not possible to track it in HA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants