HotswapProjects/HotswapAgent

final static variable values duplicates when hot swap

UyCode opened this issue · 1 comments

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

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.