Access-control boundary violations

As a professional developer, you always want your code to be secure, portable, and bug-free, which requires strict adherence to Java constructs such as encapsulation. There are occasions, such as with white box testing, that you need to break the encapsulation that the JVM mandates. This mandate permits cross-modular access.

To permit breaking the encapsulation, you can add an add-exports option in your module declaration. Here is the syntax you will use:

module com.three19.irisScan
{
- - add-exports <source-module>/<package> = <target-module>
(, <target-module> )*
}

Let's take a closer look at the preceding syntax. The <source-module> and <targetmodule> are module names, and <package> is the name of the package. Using the add-exports option permits us to violate access-control boundaries.

There are two rules regarding using the add-exports option:

  • It can be used multiple times in a module
  • Each use must be a unique pairing of <source-module> and <targetmodule>
It is not recommended that the add-exports option is used unless absolutely necessary. Its use permits dangerous access to a library module's internal API. This type of use makes your code dependent on the internal API not changing, which is beyond your control.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset