4 ms·
Makes sense and this definitely lowers the risk. However you could still end up with situations where the new method body assumes different constraints/invarian
by xg15 5y ago
Makes sense and this definitely lowers the risk. However you could still end up with situations where the new method body assumes different constraints/invariants on field values than the old code, so calling the hotswapped method on existing objects could still lead to unexpected behaviour.
Example:
A class has a private read-only field int foo that can take any value and a DoStuff() method which uses foo's value.
Now the constructor is hotswapped to validate that foo > 5 and DoStuff is hotswapped with an implementation that also assumes foo > 5.
This is all good for new objects created after the hotswap - however calling DoStuff on objects created before the swap (which might have foo <= 5) is unsafe.