4

Given:

  • Modules A and B, where B imports A.
  • Module A exports external.class1. It defines but does not export external.class1.secretProvider, internal.SharedSecrets and internal.class2 (more on these below).
  • Module A uses the SharedSecrets mechanism to grant external.class1 access to private methods in internal.class2 using external.class1.secretProvider.

I wish to grant external.class3 (defined in Module B) access to private methods in internal.class2 but seeing as internal.SharedSecrets and external.class1.secretProvider are not exported by A I have no way of doing so.

Is there a way for B to access to A's secrets without exporting them for the whole world to see?

Naman
  • 27,789
  • 26
  • 218
  • 353
Gili
  • 86,244
  • 97
  • 390
  • 689
  • 1
    Why not use a qualified export? `exports external.class1.secretProvider to B`.. If I understand the question correct that's what you're looking for. – Naman Dec 06 '18 at 14:19

1 Answers1

2

Is there a way for B to access to A's secrets without exporting them for the whole world to see?

If I am not getting the question wrong, you can use qualified exports to make sure you export those packages just to a specific (list of) module. You can do so as :

module A {
    exports external.class1.secretProvider to B;
    exports internal.SharedSecrets to B;
    // ... rest of your declarations
}
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 1
    Makes sense to me. I didn't consider this option because most tutorials I found did not cover qualified exports. I ended up finding https://www.oracle.com/corporate/features/understanding-java-9-modules.html which does. Thank you. – Gili Dec 06 '18 at 18:30