The rationale for runtime modularization
rafael.wth at gmail.com
Thu Dec 3 21:36:10 UTC 2015
I am writing this after looking into Jigsaw for about two months and after
running my open-source libraries and several enterprise applications of my
current employer using the EA builds.
In the context of these experiences, I wanted to ask for the rationale of
project Jigsaw to enforce modularization at runtime.
In the software I have searched, reflection is predominantly used for
interacting with code that is unknown during compilation. Of course,
sometimes reflection is used for abstracting code from types but this is
extremely rare as generic types pretty much cover this need.
In practice, this implies that any reflective invocation requires an
explicit module check. This check can be easily forgotten. Furthermore, the
compiler does not remind of missing edges when migrating software either.
It seems to me that the assumption for the runtime checks is that
invocations might accidentally cross module boundaries. From the code that
I looked at, I argue that this is already the primary intention when using
One might argue that the same holds for reflection on non-public types.
However, in this case I believe that security concerns are the main reason
for enforcing accessability where access can be denied by a security
manager. Modules on the other hand cannot provide additional security as
there is always an opt-out for non-modularized code to avoid such barriers.
I am sure this possibility was considered and I wonder why it was not
implemented. Looking at the very little practical relevance of heap
pollution caused by type-erasure, I believe that compile-time
modularization would work well in this case, too. The Java compiler could
enforce module boundaries while users of reflection would not be bothered
with the boundaries they intended to cross in the first place. As the most
important benefit, migration would be much easier. Libraries could add
module descriptors to pre-Java-9 bundles without needing to alter code
since runtime behavior does not longer depend on the bundling format.
Thanks for your input!
Best regards, Rafael
More information about the jigsaw-dev