Class ModuleLayer.Controller
- Enclosing class:
ModuleLayer
public static final class ModuleLayer.Controller extends Object
ModuleLayer to create module layers return a Controller that can be used to control modules in the layer. Unless otherwise specified, passing a null argument to a method in this class causes a NullPointerException to be thrown.
- API Note:
- Care should be taken with
Controllerobjects, they should never be shared with untrusted code. - Since:
- 9
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
ModuleLayer.Controller |
addExports |
Updates module source in the layer to export a package to module target. |
ModuleLayer.Controller |
addOpens |
Updates module source in the layer to open a package to module target. |
ModuleLayer.Controller |
addReads |
Updates module source in the layer to read module target. |
ModuleLayer.Controller |
enableNativeAccess |
Restricted. Enables native access for a module in the layer if the caller's module has native access. |
ModuleLayer |
layer() |
Returns the layer that this object controls. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Method Details
layer
public ModuleLayer layer()
- Returns:
- the module layer
addReads
public ModuleLayer.Controller addReads(Module source, Module target)
source in the layer to read module target. This method is a no-op if source already reads target.- Implementation Note:
-
Read edges added by this method are weak and do not prevent
targetfrom being GC'ed whensourceis strongly reachable. - Parameters:
-
source- The source module -
target- The target module to read - Returns:
- This controller
- Throws:
-
IllegalArgumentException- Ifsourceis not in the module layer - See Also:
addExports
public ModuleLayer.Controller addExports(Module source, String pn, Module target)
source in the layer to export a package to module target. This method is a no-op if source already exports the package to at least target. Exporting a package with this method does not allow the target module to reflectively set or obtain a method handle with write access to a public final field declared in a public class in the package.
- Parameters:
-
source- The source module -
pn- The package name -
target- The target module - Returns:
- This controller
- Throws:
-
IllegalArgumentException- Ifsourceis 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)
source in the layer to open a package to module target. This method is a no-op if source already opens the package to at least target. Opening a package with this method does not allow the target module to reflectively set or obtain a method handle with write access to a final field declared in a class in the package.
- Parameters:
-
source- The source module -
pn- The package name -
target- The target module - Returns:
- This controller
- Throws:
-
IllegalArgumentException- Ifsourceis 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 a restricted method of the Java platform. enableNativeAccess when access to restricted methods is enabled.- Parameters:
-
target- The module to update - Returns:
- This controller
- Throws:
-
IllegalArgumentException- Iftargetis not in the module layer -
IllegalCallerException- If the caller is in a module that does not have native access enabled - Since:
- 22
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.