Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.0
-
None
Description
When a JVM hotswaps code, it does not re-run static initializers. For some reason (I'm sure it is a good reason, I just don't know what it is), the groovy compiler moves constants referenced in methods into fields initialized from the static initializer. This code:
class A {
def foo() {
def x = 5555
}
}
produces bytecode where the 5555 is put into a field called '$const$0' in the static initializer. This means if I change it from 5555 to 6666 and recompile, the change will not be picked up by hotswap because the static initializer will not be rerun.
This is vaguely similar to the problem of call site caching but that could be addressed by calling the call site array to reinitialize on hotswap. A similar solution would work here (call a reinitialize method for constants on hotswap) if the code to initialize the constants were pulled out into a static method that was invoked from the static initializer instead of being inlined in the initializer. However, the field $const$0 is also currently marked 'final' which complicates things.
Without a change here, it doesn't appear to be possible to hotswap constant values.
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-4412 FindBugs errors for new Integer() vs. Integer.valueOf() like calls
- Closed