Class ModuleLayer.Controller

java.lang.Object
java.lang.ModuleLayer.Controller
Enclosing class:
ModuleLayer

public static final classModuleLayer.ControllerextendsObject
Controls a module layer. The static methods defined byModuleLayerto create module layers return aController that can be used tocontrol modules in the layer.

Unless otherwise specified, passing anull argument to amethod in this class causes aNullPointerException to be thrown.

API Note:
Care should be taken withController objects, theyshould never be shared with untrusted code.
Since:
9
  • Method Details

    • layer

      public ModuleLayer layer()
      Returns the layer that this object controls.
      Returns:
      the module layer
    • addReads

      public ModuleLayer.Controller addReads(Module source,Module target)
      Updates modulesource in the layer to read moduletarget. This method is a no-op ifsource alreadyreadstarget.
      Implementation Note:
      Read edges added by this method areweakand do not preventtarget from being GC'ed whensourceis strongly reachable.
      Parameters:
      source - The source module
      target - The target module to read
      Returns:
      This controller
      Throws:
      IllegalArgumentException - Ifsource is not in the module layer
      See Also:
    • addExports

      public ModuleLayer.Controller addExports(Module source,String pn,Module target)
      Updates modulesource in the layer to export a package tomoduletarget. This method is a no-op ifsourcealready exports the package to at leasttarget.
      Parameters:
      source - The source module
      pn - The package name
      target - The target module
      Returns:
      This controller
      Throws:
      IllegalArgumentException - Ifsource is not in the module layer or the package is not in the source module
      See Also:
    • addOpens

      public ModuleLayer.Controller addOpens(Module source,String pn,Module target)
      Updates modulesource in the layer to open a package tomoduletarget. This method is a no-op ifsourcealready opens the package to at leasttarget.
      Parameters:
      source - The source module
      pn - The package name
      target - The target module
      Returns:
      This controller
      Throws:
      IllegalArgumentException - Ifsource is not in the module layer or the package is not in the source module
      See Also:
    • enableNativeAccess

      public ModuleLayer.Controller enableNativeAccess(Module target)
      enableNativeAccess is arestricted method of the Java platform.
      Programs can only useenableNativeAccess when access to restricted methods is enabled.
      Restricted methods are unsafe, and, if used incorrectly, might crash the JVM or result in memory corruption.
      Enables native access for a module in the layer if the caller's modulehas native access.
      Parameters:
      target - The module to update
      Returns:
      This controller
      Throws:
      IllegalArgumentException - Iftarget is not in the module layer
      IllegalCallerException - If the caller is in a module that does not have native access enabled
      Since:
      22