I was answering this question, where I recommended utilizing exports to
syntax to prevent external consumers from accessing code that is intended for internal use between modules.
But on further reflection, the only real safety checking that modules implement is that it matches the name. Consider this example where I am implementing two modules:
module a {
exports unsafe to b
}
module b {
requires a
}
The package unsafe
contains code that would be unsafe to have exposed. Is there any way to securely export this to internal modules without exposing them externally?
In the above example, a rogue entity could simply name their module b
and would gain access to the code (not secure). The JLS doesn't seem to spell out anything that can prevent it.