APIdia Launch Partner
Top Description Inners Methods
java.lang.classfile.attribute

public sealed Interface ModuleAttribute

extends Attribute<ModuleAttribute>, ClassElement
permits BoundModuleAttribute, UnboundModuleAttribute
Known Direct Implementers
jdk.internal.classfile.impl.BoundAttribute.BoundModuleAttribute, jdk.internal.classfile.impl.UnboundAttribute.UnboundModuleAttribute
Imports
java.lang.classfile.Attribute, .AttributeMapper, .Attributes, .ClassElement, .ClassFile, .ClassModel, java.lang.classfile.constantpool.ClassEntry, .ModuleEntry, .Utf8Entry, java.lang.constant.ClassDesc, .ModuleDesc, .PackageDesc, java.lang.invoke.MethodHandles, java.lang.module.ModuleDescriptor, java.lang.reflect.AccessFlag, java.util.Collection, .List, .Optional, .ServiceLoader, .Set, java.util.function.Consumer, jdk.internal.classfile.impl.BoundAttribute, .ModuleAttributeBuilderImpl, .UnboundAttribute, .Util

Models the Module attribute (JVMS 4.7.25), which always appears on classes that represent module descriptors.

This attribute only appears on classes, and does not permit multiple instances in a class. It has a data dependency on the constant pool.

The attribute was introduced in the Java SE Platform version 9, major version 53.

Since
24
Java Virtual Machine Specification
4.7.25 The Module Attribute
See Also
Attributes#module(), ModuleDescriptor

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Method Summary

Modifier and TypeMethod and Description
public List<ModuleExportInfo>

Returns:

the packages exported by this module
exports
()

Returns the packages exported by this module.

public default boolean

Returns:

true if the flag is set
has
(AccessFlag
the module flag
flag
)

Tests presence of module flag.

public default Set<AccessFlag>

Returns:

the module flags of the module, as a set of enum constants
moduleFlags
()

Returns the module flags of the module, as a set of enum constants.

public int

Returns:

the module flags of the module, as a bit mask
moduleFlagsMask
()

Returns the module flags of the module, as a bit mask.

public ModuleEntry

Returns:

the name of the module
moduleName
()

Returns the name of the module.

public Optional<Utf8Entry>

Returns:

the version of the module, if present
moduleVersion
()

Returns the version of the module, if present.

public static ModuleAttribute

Returns:

a Module attribute
of
(ModuleEntry
the module name
moduleName
,
int
the module flags
moduleFlags
,
Utf8Entry
the module version, may be null
moduleVersion
,
Collection<ModuleRequireInfo>
the required packages
requires
,
Collection<ModuleExportInfo>
the exported packages
exports
,
Collection<ModuleOpenInfo>
the opened packages
opens
,
Collection<ClassEntry>
the consumed services
uses
,
Collection<ModuleProvideInfo>
the provided services
provides
)

Returns a Module attribute.

public static ModuleAttribute

Returns:

a Module attribute
of
(ModuleDesc
the module name
moduleName
,
Consumer<ModuleAttribute.ModuleAttributeBuilder>
a handler that receives a ModuleAttributeBuilder
attrHandler
)

Returns a Module attribute.

public static ModuleAttribute

Returns:

a Module attribute
of
(ModuleEntry
the module name
moduleName
,
Consumer<ModuleAttribute.ModuleAttributeBuilder>
a handler that receives a ModuleAttributeBuilder
attrHandler
)

Returns a Module attribute.

public List<ModuleOpenInfo>

Returns:

the packages opened by this module
opens
()

Returns the packages opened by this module.

public List<ModuleProvideInfo>

Returns:

the service implementations provided by this module
provides
()

Returns the service implementations provided by this module.

public List<ModuleRequireInfo>

Returns:

the modules required by this module
requires
()

Returns the modules required by this module.

public List<ClassEntry>

Returns:

the services used by this module
uses
()

Returns the services used by this module.

Inherited from java.lang.classfile.Attribute:
attributeMapperattributeName

Method Detail

exportsback to summary
public List<ModuleExportInfo> exports()

Returns the packages exported by this module.

Returns:List<ModuleExportInfo>

the packages exported by this module

See Also
ModuleDescriptor#packages()
hasback to summary
public default boolean has(AccessFlag flag)

Tests presence of module flag.

Parameters
flag:AccessFlag

the module flag

Returns:boolean

true if the flag is set

See Also
AccessFlag.Location#MODULE
moduleFlagsback to summary
public default Set<AccessFlag> moduleFlags()

Returns the module flags of the module, as a set of enum constants.

Returns:Set<AccessFlag>

the module flags of the module, as a set of enum constants

Exceptions
IllegalArgumentException:
if the flags mask has any undefined bit set
See Also
ModuleDescriptor#accessFlags(), AccessFlag.Location#MODULE
moduleFlagsMaskback to summary
public int moduleFlagsMask()

Returns the module flags of the module, as a bit mask. It is a u2 value.

Returns:int

the module flags of the module, as a bit mask

See Also
ModuleDescriptor#modifiers(), AccessFlag.Location#MODULE
moduleNameback to summary
public ModuleEntry moduleName()

Returns the name of the module.

Returns:ModuleEntry

the name of the module

See Also
ModuleDescriptor#name()
moduleVersionback to summary
public Optional<Utf8Entry> moduleVersion()

Returns the version of the module, if present.

Returns:Optional<Utf8Entry>

the version of the module, if present

See Also
ModuleDescriptor#version()
ofback to summary
public static ModuleAttribute of(ModuleEntry moduleName, int moduleFlags, Utf8Entry moduleVersion, Collection<ModuleRequireInfo> requires, Collection<ModuleExportInfo> exports, Collection<ModuleOpenInfo> opens, Collection<ClassEntry> uses, Collection<ModuleProvideInfo> provides)

Returns a Module attribute.

Parameters
moduleName:ModuleEntry

the module name

moduleFlags:int

the module flags

moduleVersion:Utf8Entry

the module version, may be null

requires:Collection<ModuleRequireInfo>

the required packages

exports:Collection<ModuleExportInfo>

the exported packages

opens:Collection<ModuleOpenInfo>

the opened packages

uses:Collection<ClassEntry>

the consumed services

provides:Collection<ModuleProvideInfo>

the provided services

Returns:ModuleAttribute

a Module attribute

Exceptions
IllegalArgumentException:
if moduleFlags is not u2 or any of the collections has a size over the limit of u2
ofback to summary
public static ModuleAttribute of(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)

Returns a Module attribute.

Parameters
moduleName:ModuleDesc

the module name

attrHandler:Consumer<ModuleAttribute.ModuleAttributeBuilder>

a handler that receives a ModuleAttributeBuilder

Returns:ModuleAttribute

a Module attribute

Exceptions
IllegalArgumentException:
if the information from the handler exceeds the class file format limit, such as a list with size over the limit of u2
ofback to summary
public static ModuleAttribute of(ModuleEntry moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)

Returns a Module attribute.

Parameters
moduleName:ModuleEntry

the module name

attrHandler:Consumer<ModuleAttribute.ModuleAttributeBuilder>

a handler that receives a ModuleAttributeBuilder

Returns:ModuleAttribute

a Module attribute

opensback to summary
public List<ModuleOpenInfo> opens()

Returns the packages opened by this module.

API Note

Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See MethodHandles#privateLookupIn for more details.

Returns:List<ModuleOpenInfo>

the packages opened by this module

See Also
ModuleDescriptor#opens()
providesback to summary
public List<ModuleProvideInfo> provides()

Returns the service implementations provided by this module.

Returns:List<ModuleProvideInfo>

the service implementations provided by this module

See Also
ModuleDescriptor#provides()
requiresback to summary
public List<ModuleRequireInfo> requires()

Returns the modules required by this module.

Returns:List<ModuleRequireInfo>

the modules required by this module

See Also
ModuleDescriptor#requires()
usesback to summary
public List<ClassEntry> uses()

Returns the services used by this module. Services may be discovered via ServiceLoader.

Returns:List<ClassEntry>

the services used by this module

See Also
ModuleDescriptor#uses()
java.lang.classfile.attribute back to summary

public sealed Interface ModuleAttribute.ModuleAttributeBuilder

permits ModuleAttributeBuilderImpl
Known Direct Implementers
jdk.internal.classfile.impl.ModuleAttributeBuilderImpl

A builder for Module attributes.
Since
24
Java Virtual Machine Specification
4.7.25 The Module Attribute
See Also
ModuleDescriptor.Builder

Method Summary

Modifier and TypeMethod and Description
public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
exports
(PackageDesc
the exported package
pkge
,
int
the export flags
exportsFlagsMask
,
ModuleDesc...
the modules to export to, or empty for an unqualified export
exportsToModules
)

Adds an exported package.

public default ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
exports
(PackageDesc
the exported package
pkge
,
Collection<AccessFlag>
the export flags
exportsFlags
,
ModuleDesc...
the modules to export to, or empty for an unqualified export
exportsToModules
)

Adds an exported package.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
exports
(ModuleExportInfo
the module export info
exports
)

Adds an exported package.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
moduleFlags
(int
the module flags
flagsMask
)

Sets the module flags.

public default ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
moduleFlags
(AccessFlag...
the module flags
moduleFlags
)

Sets the module flags.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
moduleName
(ModuleDesc
the module name
moduleName
)

Sets the module name.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
moduleVersion
(String
the module version, may be null
version
)

Sets the module version, which may be null.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
opens
(PackageDesc
the opened package
pkge
,
int
the open package flags
opensFlagsMask
,
ModuleDesc...
the modules to open to, or empty for an unqualified open
opensToModules
)

Opens a package.

public default ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
opens
(PackageDesc
the opened package
pkge
,
Collection<AccessFlag>
the open package flags
opensFlags
,
ModuleDesc...
the modules to open to, or empty for an unqualified open
opensToModules
)

Opens a package.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
opens
(ModuleOpenInfo
the module open info
opens
)

Opens a package.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
provides
(ClassDesc
the service class provided
service
,
ClassDesc...
the implementation classes
implClasses
)

Declares provision of a service.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
provides
(ModuleProvideInfo
the module provides info
provides
)

Declares provision of a service.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
requires
(ModuleDesc
the required module
module
,
int
the requires flags
requiresFlagsMask
,
String
the required module version, may be null
version
)

Adds a module requirement.

public default ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
requires
(ModuleDesc
the required module
module
,
Collection<AccessFlag>
the requires flags
requiresFlags
,
String
the required module version, may be null
version
)

Adds a module requirement.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
requires
(ModuleRequireInfo
the module require info
requires
)

Adds module requirement.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
uses
(ClassDesc
the service class used
service
)

Declares use of a service.

public ModuleAttribute.ModuleAttributeBuilder

Returns:

this builder
uses
(ClassEntry
the service class used
uses
)

Declares use of a service.

Method Detail

exportsback to summary
public ModuleAttribute.ModuleAttributeBuilder exports(PackageDesc pkge, int exportsFlagsMask, ModuleDesc... exportsToModules)

Adds an exported package.

Parameters
pkge:PackageDesc

the exported package

exportsFlagsMask:int

the export flags

exportsToModules:ModuleDesc[]

the modules to export to, or empty for an unqualified export

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if the number of modules exceeds the limit of u2
exportsback to summary
public default ModuleAttribute.ModuleAttributeBuilder exports(PackageDesc pkge, Collection<AccessFlag> exportsFlags, ModuleDesc... exportsToModules)

Adds an exported package.

Parameters
pkge:PackageDesc

the exported package

exportsFlags:Collection<AccessFlag>

the export flags

exportsToModules:ModuleDesc[]

the modules to export to, or empty for an unqualified export

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if any flag cannot be applied to the AccessFlag.Location#MODULE_EXPORTS location or the number of modules exceeds the limit of u2
exportsback to summary
public ModuleAttribute.ModuleAttributeBuilder exports(ModuleExportInfo exports)

Adds an exported package.

Parameters
exports:ModuleExportInfo

the module export info

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

moduleFlagsback to summary
public ModuleAttribute.ModuleAttributeBuilder moduleFlags(int flagsMask)

Sets the module flags.

Parameters
flagsMask:int

the module flags

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if flagsMask is not u2
moduleFlagsback to summary
public default ModuleAttribute.ModuleAttributeBuilder moduleFlags(AccessFlag... moduleFlags)

Sets the module flags.

Parameters
moduleFlags:AccessFlag[]

the module flags

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if any flag cannot be applied to the AccessFlag.Location#MODULE location
moduleNameback to summary
public ModuleAttribute.ModuleAttributeBuilder moduleName(ModuleDesc moduleName)

Sets the module name.

Parameters
moduleName:ModuleDesc

the module name

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

moduleVersionback to summary
public ModuleAttribute.ModuleAttributeBuilder moduleVersion(String version)

Sets the module version, which may be null.

Parameters
version:String

the module version, may be null

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

opensback to summary
public ModuleAttribute.ModuleAttributeBuilder opens(PackageDesc pkge, int opensFlagsMask, ModuleDesc... opensToModules)

Opens a package.

API Note

Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See MethodHandles#privateLookupIn for more details.

Parameters
pkge:PackageDesc

the opened package

opensFlagsMask:int

the open package flags

opensToModules:ModuleDesc[]

the modules to open to, or empty for an unqualified open

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if the number of modules exceeds the limit of u2
opensback to summary
public default ModuleAttribute.ModuleAttributeBuilder opens(PackageDesc pkge, Collection<AccessFlag> opensFlags, ModuleDesc... opensToModules)

Opens a package.

API Note

Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See MethodHandles#privateLookupIn for more details.

Parameters
pkge:PackageDesc

the opened package

opensFlags:Collection<AccessFlag>

the open package flags

opensToModules:ModuleDesc[]

the modules to open to, or empty for an unqualified open

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if any flag cannot be applied to the AccessFlag.Location#MODULE_OPENS location, or if the number of modules exceeds the limit of u2
opensback to summary
public ModuleAttribute.ModuleAttributeBuilder opens(ModuleOpenInfo opens)

Opens a package.

API Note

Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See MethodHandles#privateLookupIn for more details.

Parameters
opens:ModuleOpenInfo

the module open info

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

providesback to summary
public ModuleAttribute.ModuleAttributeBuilder provides(ClassDesc service, ClassDesc... implClasses)

Declares provision of a service.

Parameters
service:ClassDesc

the service class provided

implClasses:ClassDesc[]

the implementation classes

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if service or any of the implClasses represents a primitive type, or the number of implementations exceeds the limit of u2
providesback to summary
public ModuleAttribute.ModuleAttributeBuilder provides(ModuleProvideInfo provides)

Declares provision of a service.

Parameters
provides:ModuleProvideInfo

the module provides info

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

requiresback to summary
public ModuleAttribute.ModuleAttributeBuilder requires(ModuleDesc module, int requiresFlagsMask, String version)

Adds a module requirement.

Parameters
module:ModuleDesc

the required module

requiresFlagsMask:int

the requires flags

version:String

the required module version, may be null

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

requiresback to summary
public default ModuleAttribute.ModuleAttributeBuilder requires(ModuleDesc module, Collection<AccessFlag> requiresFlags, String version)

Adds a module requirement.

Parameters
module:ModuleDesc

the required module

requiresFlags:Collection<AccessFlag>

the requires flags

version:String

the required module version, may be null

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if any flag cannot be applied to the AccessFlag.Location#MODULE_REQUIRES location
requiresback to summary
public ModuleAttribute.ModuleAttributeBuilder requires(ModuleRequireInfo requires)

Adds module requirement.

Parameters
requires:ModuleRequireInfo

the module require info

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

usesback to summary
public ModuleAttribute.ModuleAttributeBuilder uses(ClassDesc service)

Declares use of a service.

Parameters
service:ClassDesc

the service class used

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder

Exceptions
IllegalArgumentException:
if service represents a primitive type
usesback to summary
public ModuleAttribute.ModuleAttributeBuilder uses(ClassEntry uses)

Declares use of a service.

Parameters
uses:ClassEntry

the service class used

Returns:ModuleAttribute.ModuleAttributeBuilder

this builder