ENT-11328: Update node initialisation to be flexible if JDK modules are not open to reflection #7640
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was work-in-progress, exploratory PR
The overall goal was to eliminate, or reduce as much as possible, the need for the JVM
--add-opens
flags when running the unit tests. The reason for this is it will also affect users when they write tests using the mock network or the in-process node driver. The users will essentially need to copy most of the same flags the node uses when it runs. This isn't a very good user experience, though perhaps manageable with some documentation.The process I took was to remove the
node-jvm-args.txt
from thejvmArgs
for all unit tests, and only added for tests which absolutely needed them, such as checkpoint serialisation tests. This later example had its own module createdcheckpoint-tests
.The main reason the flags are needed is due to Kryo serialisation of checkpoints, when it tries to access private members of the JDK via reflection. The access is typically needed by the Kryo serialisers, so instead of adding these serialisers, it first checks if it has access to do so and then adds them. This is primarily done by the new
Class<*>.isPackageOpen
. If the package is open, which will be the case with a proper Corda node process, then the serialiser is added as usual. If it's not open, which will be the case with mock nodes, then it registers a fall back serialiser viaKryo.registerAsInaccessible
. This will try to write out checkpoints using a backend serialiser, but it will not be able to deserialise the correct type. For example, it will serialise anunmodifiableList
using a normalList
serialiser, but it can't deserialise it since it needs access to internals of theunmodifiableList
class. So instead during checkpoint deserialisation it will throw an exception with a help message:Since most mock node tests will not be restarting nodes, which is when checkpoints are deserialised, this will not affect majority of tests.
There are other changes to reduce the need to reflect on JDK internals.