APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.lang

public final Class Module

extends Object
implements AnnotatedElement
Class Inheritance
All Implemented Interfaces
java.lang.reflect.AnnotatedElement
Imports
java.io.IOException, .InputStream, java.lang.annotation.Annotation, java.lang.module.Configuration, .ModuleReference, .ModuleDescriptor, .ModuleDescriptor.Exports, .ModuleDescriptor.Opens, .ModuleDescriptor.Version, .ResolvedModule, java.lang.reflect.AccessFlag, .AnnotatedElement, .Field, java.net.URI, .URL, java.security.CodeSource, java.util.HashMap, .HashSet, .List, .Map, .Objects, .Optional, .Set, java.util.concurrent.ConcurrentHashMap, java.util.function.Function, java.util.stream.Collectors, .Stream, java.lang.classfile.AccessFlags, .Attribute, .ClassFile, java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute, jdk.internal.loader.BuiltinClassLoader, .BootLoader, .ClassLoaders, jdk.internal.misc.CDS, .Unsafe, .VM, jdk.internal.module.ModuleBootstrap, .ModuleLoaderMap, .ServicesCatalog, .Resources, jdk.internal.reflect.CallerSensitive, .Reflection, jdk.internal.vm.annotation.AOTSafeClassInitializer, .Stable

Represents a run-time module, either named or unnamed.

Named modules have a name and are constructed by the Java Virtual Machine when a graph of modules is defined to the Java virtual machine to create a module layer.

An unnamed module does not have a name. There is an unnamed module for each ClassLoader, obtained by invoking its getUnnamedModule method. All types that are not in a named module are members of their defining class loader's unnamed module.

The package names that are parameters or returned by methods defined in this class are the fully-qualified names of the packages as defined in section 6.5.3 of The Java Language Specification, for example, "java.lang".

Unless otherwise specified, passing a null argument to a method in this class causes a NullPointerException to be thrown.

Since
9
Java Language Specification
7.7 Module Declarations
See Also
Class#getModule()

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
Module.EnableFinalMutation

This class exists to avoid using Unsafe during early initialization of Module.

private static class
Module.EnableNativeAccess

This class is used to be able to bootstrap without using Unsafe in the outer Module class as that would create a circular initializer dependency.

private static class
Module.ReflectionData

The holder of data structures to support readability, exports, and service use added at runtime with the reflective APIs.

Field Summary

Modifier and TypeField and Description
private static final Module
private static final Set<Module>
private final ModuleDescriptor
private boolean
private boolean
private static final Module
private static final Set<Module>
private volatile Map<String, Set<Module>>
private final ModuleLayer
private final ClassLoader
private volatile Class<?>
private final String
private volatile Map<String, Set<Module>>
private volatile Set<Module>

Constructor Summary

AccessConstructor and Description
pack-priv
Module(ModuleLayer layer, ClassLoader loader, ModuleDescriptor descriptor, URI uri)

Creates a new named Module.

pack-priv
Module(ClassLoader loader)

Create the unnamed Module for the given ClassLoader.

pack-priv
Module(ClassLoader loader, ModuleDescriptor descriptor)

Creates a named module but without defining the module to the VM.

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
addEnableFinalMutationToAllUnnamed()

Enable code in all unnamed modules to mutate final instance fields.

pack-priv static void
addEnableNativeAccessToAllUnnamed()

Enable code in all unnamed modules to access restricted methods.

public Module

Returns:

this module
addExports
(String
The package name
pn
,
Module
The module
other
)

If the caller's module is this module then update this module to export the given package to the given module.

private static native void
private static native void
private static native void
public Module

Returns:

this module
addOpens
(String
The package name
pn
,
Module
The module
other
)

If this module has opened the given package to at least the caller module, then update this module to also open the package to the given module.

public Module

Returns:

this module
addReads
(Module
The other module
other
)

If the caller's module is this module then update this module to read the given module.

private static native void
public Module

Returns:

this module
addUses
(Class<?>
The service type
service
)

If the caller's module is this module then update this module to add a service dependence on the given service type.

private boolean
allows(Set<Module> targets, Module module)

Returns true if targets is non-null and contains EVERYONE_MODULE or the given module.

public boolean

Returns:

true if this module reads other
canRead
(Module
The other module
other
)

Indicates if this module reads the given module.

public boolean

Returns:

true if this module uses service type st
canUse
(Class<?>
The service type
service
)

Indicates if this module has a service dependence on the given service type.

private static native void
defineModule0(Module module, boolean isOpen, String version, String location, Object[] pns)

pack-priv static Map<String, Module>

Returns:

a map of module name to runtime Module
defineModules
(Configuration cf, Function<String, ClassLoader> clf, ModuleLayer layer)

Defines all module in a configuration to the runtime.

pack-priv void
ensureNativeAccess(Class<?> owner, String methodName, Class<?> currentClass, boolean jni)

private static Module
findModule(ModuleLayer parent, ResolvedModule resolvedModule)

Find the runtime Module corresponding to the given ResolvedModule in the given parent layer (or its parents).

private static Module
findModule(String
The target module to find
target
,
Map<String, Module>
The modules in parent layers that are read
nameToSource
,
Map<String, Module>
The modules in the layer under construction
nameToModule
,
List<ModuleLayer>
The parent layers
parents
)

Find the runtime Module with the given name.

public <T extends Annotation> T
getAnnotation(Class<T> annotationClass)

Implements java.lang.reflect.AnnotatedElement.getAnnotation.

Returns this element's annotation for the specified type if such an annotation is present, else null.

public Annotation[]
getAnnotations()

Implements java.lang.reflect.AnnotatedElement.getAnnotations.

Returns annotations that are present on this element.

private Module
getCallerModule(Class<?> caller)

Returns the module that a given caller class is a member of.

public ClassLoader

Returns:

The class loader for this module
getClassLoader
()

Returns the ClassLoader for this module.

public Annotation[]
getDeclaredAnnotations()

Implements java.lang.reflect.AnnotatedElement.getDeclaredAnnotations.

Returns annotations that are directly present on this element.

public ModuleDescriptor

Returns:

The module descriptor for this module
getDescriptor
()

Returns the module descriptor for this module or null if this module is an unnamed module.

public ModuleLayer

Returns:

The module layer that contains this module
getLayer
()

Returns the module layer that contains this module or null if this module is not in a module layer.

public String

Returns:

The module name
getName
()

Returns the module name or null if this module is an unnamed module.

public Set<String>

Returns:

the set of the package names of the packages in this module
getPackages
()

Returns the set of package names for the packages in this module.

public InputStream

Returns:

An input stream for reading the resource or null
getResourceAsStream
(String
The resource name
name
)

Returns an input stream for reading a resource in this module.

pack-priv Module
implAddEnableNativeAccess()

Update this module to allow access to restricted methods.

pack-priv void
implAddExports(String pn)

Updates this module to export a package unconditionally.

pack-priv void
implAddExports(String pn, Module other)

Updates this module to export a package to another module.

pack-priv void
implAddExportsNoSync(String pn)

Updates this export to export a package unconditionally without notifying the VM.

pack-priv void
implAddExportsNoSync(String pn, Module other)

Updates a module to export a package to another module without notifying the VM.

private void
implAddExportsOrOpens(String
package name
pn
,
Module
the module to export/open the package to
other
,
boolean
true to open, false to export
open
,
boolean
true if exported/opened reflectively
reflectively
,
boolean
true to update the VM
syncVM
)

Updates a module to export or open a module to another module.

pack-priv void
implAddExportsToAllUnnamed(String pn)

Updates this module to export a package to all unnamed modules.

pack-priv void
implAddOpens(String pn)

Updates this module to open a package unconditionally.

pack-priv void
implAddOpens(String pn, Module other)

Updates this module to open a package to another module.

pack-priv void
implAddOpensToAllUnnamed(String pn)

Updates this module to open a package to all unnamed modules.

pack-priv void
implAddReads(Module other)

Updates this module to read another module.

private void
implAddReads(Module other, boolean syncVM)

Makes the given Module readable to this module.

pack-priv void
implAddReadsAllUnnamed()

Updates this module to read all unnamed modules.

pack-priv void
implAddReadsNoSync(Module other)

Updates this module to read another module without notifying the VM.

pack-priv void
implAddUses(Class<?> service)

Update this module to add a service dependence on the given service type.

private boolean
implIsExportedOrOpen(String pn, Module other, boolean open)

Returns true if this module exports or opens the given package to the given module.

private static void
initExports(Module
the module
m
,
Map<String, Module>
map of module name to Module (for qualified exports)
nameToModule
)

Initialize/setup a module's exports.

private static void
initExportsAndOpens(Module
the module
m
,
Map<String, Module>
map of module name to Module for modules that m reads
nameToSource
,
Map<String, Module>
map of module name to Module for modules in the layer under construction
nameToModule
,
List<ModuleLayer>
the parent layers
parents
)

Initialize/setup a module's exports.

private boolean
isExplicitlyExportedOrOpened(String pn, Module other, boolean open)

Returns true if this module exports or opens a package to the given module via its module declaration or CLI options.

public boolean

Returns:

true if this module exports the package to at least the given module
isExported
(String
The package name
pn
,
Module
The other module
other
)

Returns true if this module exports the given package to at least the given module.

public boolean

Returns:

true if this module exports the package unconditionally
isExported
(String
The package name
pn
)

Returns true if this module exports the given package unconditionally.

pack-priv boolean
isFinalMutationEnabled()

Return true if code in this module is allowed to mutate final instance fields.

public boolean

Returns:

true if this is a named module
isNamed
()

Returns true if this module is a named module.

public boolean

Returns:

true if this module can access restricted methods.
isNativeAccessEnabled
()

Returns true if this module can access restricted methods.

public boolean

Returns:

true if this module has opened the package to at least the given module
isOpen
(String
The package name
pn
,
Module
The other module
other
)

Returns true if this module has opened a package to at least the given module.

public boolean

Returns:

true if this module has opened the package unconditionally
isOpen
(String
The package name
pn
)

Returns true if this module has opened a package unconditionally.

pack-priv boolean
isReflectivelyExported(String pn, Module other)

Returns true if this module reflectively exports the given package to the given module.

private boolean
isReflectivelyExportedOrOpened(String pn, Module other, boolean open)

Returns true if this module reflectively exports or opens the given package to the given module.

pack-priv boolean
isReflectivelyOpened(String pn, Module other)

Returns true if this module reflectively opens the given package to the given module.

pack-priv boolean
isStaticallyExported(String pn, Module other)

Returns true if this module statically exports a package to the given module.

private boolean
isStaticallyExportedOrOpened(String pn, Module other, boolean open)

Returns true if this module exports or opens a package to the given module via its module declaration or CLI options.

pack-priv boolean
isStaticallyOpened(String pn, Module other)

Returns true if this module statically opens a package to the given module.

private Class<?>
private Class<?>
loadModuleInfoClass(InputStream in)

Loads module-info.class as a package-private interface in a class loader that is a child of this module's class loader.

private Module
private Class<?>
public String

Returns:

The string representation of this module
toString
()

Overrides java.lang.Object.toString.

Returns the string representation of this module.

pack-priv boolean
tryEnableFinalMutation()

Enable code in this named module to mutate final instance fields.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait