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

public sealed Interface ClassFile

permits ClassFileImpl
Known Direct Implementers
jdk.internal.classfile.impl.ClassFileImpl
Imports
java.io.IOException, java.lang.classfile.AttributeMapper.AttributeStability, java.lang.classfile.attribute.CharacterRangeInfo, .CodeAttribute, .LocalVariableInfo, .LocalVariableTypeInfo, .ModuleAttribute, .StackMapTableAttribute, .UnknownAttribute, java.lang.classfile.constantpool.ClassEntry, .ConstantPoolBuilder, .Utf8Entry, java.lang.classfile.instruction.BranchInstruction, .CharacterRange, .DiscontinuedInstruction, .ExceptionCatch, .LineNumber, .LocalVariable, .LocalVariableType, java.lang.constant.ClassDesc, java.lang.reflect.AccessFlag, .ClassFileFormatVersion, java.nio.file.Files, .Path, java.util.List, java.util.function.Consumer, .Function, jdk.internal.classfile.impl.ClassFileImpl, .TemporaryConstantPool

Provides ability to parse, transform, and generate class files. A ClassFile is a context with a set of options that condition how parsing and generation are done.
Since
24

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ClassFile.AttributeMapperOption

The option describing user-defined attributes for parsing class files.

public static enum
ClassFile.AttributesProcessingOption

The option describing whether to retain or discard attributes that cannot verify their correctness after a transformation.

public static interface
ClassFile.ClassHierarchyResolverOption

The option describing the class hierarchy resolver to use when generating stack maps or verifying classes.

public static enum
ClassFile.ConstantPoolSharingOption

Option describing whether to extend from the original constant pool when transforming a class file.

public static enum
ClassFile.DeadCodeOption

The option describing whether to patch out unreachable code for stack map generation.

public static enum
ClassFile.DeadLabelsOption

The option describing whether to filter unbound labels and drop their enclosing structures if possible.

public static enum
ClassFile.DebugElementsOption

The option describing whether to process or discard debug PseudoInstructions in the traversal of a CodeModel or a CodeBuilder.

public static enum
ClassFile.LineNumbersOption

The option describing whether to process or discard LineNumbers in the traversal of a CodeModel or a CodeBuilder.

public static interface
ClassFile.Option

An option that affects the parsing or writing of class files.

public static enum
ClassFile.ShortJumpsOption

The option describing whether to automatically rewrite short jumps to equivalent instructions when necessary.

public static enum
ClassFile.StackMapsOption

The option describing whether to generate stack maps.

Field Summary

Modifier and TypeField and Description
public static final int
ACC_ABSTRACT

The bit mask of AccessFlag#ABSTRACT access and property modifier.

public static final int
ACC_ANNOTATION

The bit mask of AccessFlag#ANNOTATION access and property modifier.

public static final int
ACC_BRIDGE

The bit mask of AccessFlag#BRIDGE access and property modifier.

public static final int
ACC_ENUM

The bit mask of AccessFlag#ENUM access and property modifier.

public static final int
ACC_FINAL

The bit mask of AccessFlag#FINAL access and property modifier.

public static final int
ACC_INTERFACE

The bit mask of AccessFlag#INTERFACE access and property modifier.

public static final int
ACC_MANDATED

The bit mask of AccessFlag#MANDATED access and property modifier.

public static final int
ACC_MODULE

The bit mask of AccessFlag#MODULE access and property modifier.

public static final int
ACC_NATIVE

The bit mask of AccessFlag#NATIVE access and property modifier.

public static final int
ACC_OPEN

The bit mask of AccessFlag#OPEN access and property modifier.

public static final int
ACC_PRIVATE

The bit mask of AccessFlag#PRIVATE access and property modifier.

public static final int
ACC_PROTECTED

The bit mask of AccessFlag#PROTECTED access and property modifier.

public static final int
ACC_PUBLIC

The bit mask of AccessFlag#PUBLIC access and property modifier.

public static final int
ACC_STATIC

The bit mask of AccessFlag#STATIC access and property modifier.

public static final int
ACC_STATIC_PHASE

The bit mask of AccessFlag#STATIC_PHASE access and property modifier.

public static final int
ACC_STRICT

The bit mask of AccessFlag#STRICT access and property modifier.

public static final int
ACC_SUPER

The bit mask of AccessFlag#SUPER access and property modifier.

public static final int
ACC_SYNCHRONIZED

The bit mask of AccessFlag#SYNCHRONIZED access and property modifier.

public static final int
ACC_SYNTHETIC

The bit mask of AccessFlag#SYNTHETIC access and property modifier.

public static final int
ACC_TRANSIENT

The bit mask of AccessFlag#TRANSIENT access and property modifier.

public static final int
ACC_TRANSITIVE

The bit mask of AccessFlag#TRANSITIVE access and property modifier.

public static final int
ACC_VARARGS

The bit mask of AccessFlag#VARARGS access and property modifier.

public static final int
ACC_VOLATILE

The bit mask of AccessFlag#VOLATILE access and property modifier.

public static final int
JAVA_10_VERSION

The class major version introduced by Java SE 10, .

public static final int
JAVA_11_VERSION

The class major version introduced by Java SE 11, .

public static final int
JAVA_12_VERSION

The class major version introduced by Java SE 12, .

public static final int
JAVA_13_VERSION

The class major version introduced by Java SE 13, .

public static final int
JAVA_14_VERSION

The class major version introduced by Java SE 14, .

public static final int
JAVA_15_VERSION

The class major version introduced by Java SE 15, .

public static final int
JAVA_16_VERSION

The class major version introduced by Java SE 16, .

public static final int
JAVA_17_VERSION

The class major version introduced by Java SE 17, .

public static final int
JAVA_18_VERSION

The class major version introduced by Java SE 18, .

public static final int
JAVA_19_VERSION

The class major version introduced by Java SE 19, .

public static final int
JAVA_1_VERSION

The class major version of the initial version of Java, .

public static final int
JAVA_20_VERSION

The class major version introduced by Java SE 20, .

public static final int
JAVA_21_VERSION

The class major version introduced by Java SE 21, .

public static final int
JAVA_22_VERSION

The class major version introduced by Java SE 22, .

public static final int
JAVA_23_VERSION

The class major version introduced by Java SE 23, .

public static final int
JAVA_24_VERSION

The class major version introduced by Java SE 24, .

public static final int
JAVA_25_VERSION

The class major version introduced by Java SE 25, .

public static final int
JAVA_26_VERSION

The class major version introduced by Java SE 26, .

public static final int
JAVA_27_VERSION

The class major version introduced by Java SE 27, .

public static final int
JAVA_2_VERSION

The class major version introduced by Java 2 SE 1.2, .

public static final int
JAVA_3_VERSION

The class major version introduced by Java 2 SE 1.3, .

public static final int
JAVA_4_VERSION

The class major version introduced by Java 2 SE 1.4, .

public static final int
JAVA_5_VERSION

The class major version introduced by Java 2 SE 5.0, .

public static final int
JAVA_6_VERSION

The class major version introduced by Java SE 6, .

public static final int
JAVA_7_VERSION

The class major version introduced by Java SE 7, .

public static final int
JAVA_8_VERSION

The class major version introduced by Java SE 8, .

public static final int
JAVA_9_VERSION

The class major version introduced by Java SE 9, .

public static final int
MAGIC_NUMBER

The magic number identifying the class file format, "0x-35014542".

public static final int
PREVIEW_MINOR_VERSION

A minor version number indicating a class uses preview features of a Java SE release since 12, for major versions 56 and above.

Method Summary

Modifier and TypeMethod and Description
public default byte[]

Returns:

the class file bytes
build
(ClassDesc
the name of the class to build
thisClass
,
Consumer<? super ClassBuilder>
a handler that receives a ClassBuilder
handler
)

Builds a class file into a byte array.

public byte[]

Returns:

the class file bytes
build
(ClassEntry
the name of the class to build
thisClassEntry
,
ConstantPoolBuilder
the constant pool builder
constantPool
,
Consumer<? super ClassBuilder>
a handler that receives a ClassBuilder
handler
)

Builds a class file into a byte array using the provided constant pool builder.

public default byte[]

Returns:

the class file bytes
buildModule
(ModuleAttribute
the Module attribute
moduleAttribute
)

Builds a module descriptor into a byte array.

public default byte[]

Returns:

the class file bytes
buildModule
(ModuleAttribute
the Module attribute
moduleAttribute
,
Consumer<? super ClassBuilder>
a handler that receives a ClassBuilder
handler
)

Builds a module descriptor into a byte array.

public default void
buildModuleTo(Path
the file to write
path
,
ModuleAttribute
the Module attribute
moduleAttribute
)

Builds a module descriptor into a file in a file system.

public default void
buildModuleTo(Path
the file to write
path
,
ModuleAttribute
the Module attribute
moduleAttribute
,
Consumer<? super ClassBuilder>
a handler that receives a ClassBuilder
handler
)

Builds a module descriptor into a file in a file system.

public default void
buildTo(Path
the path to the file to write
path
,
ClassDesc
the name of the class to build
thisClass
,
Consumer<ClassBuilder>
a handler that receives a ClassBuilder
handler
)

Builds a class file into a file in a file system.

public default void
buildTo(Path
the path to the file to write
path
,
ClassEntry
the name of the class to build
thisClassEntry
,
ConstantPoolBuilder
the constant pool builder
constantPool
,
Consumer<? super ClassBuilder>
a handler that receives a ClassBuilder
handler
)

Builds a class file into a file in a file system using the provided constant pool builder.

public static int

Returns:

the latest class major version supported by the current runtime
latestMajorVersion
()

Returns the latest class major version supported by the current runtime.

public static int

Returns:

the latest class minor version supported by the current runtime
latestMinorVersion
()

Returns the latest class minor version supported by the current runtime.

public static ClassFile

Returns:

a context with default options
of
()

Returns a context with default options.

public static ClassFile

Returns:

a context with options altered from the default
of
(ClassFile.Option...
the desired processing options
options
)

Returns a context with options altered from the default.

public ClassModel

Returns:

the class model
parse
(byte[]
the bytes of the class file
bytes
)

Parses a class file into a ClassModel.

public default ClassModel

Returns:

the class model
parse
(Path
the path to the class file
path
)

Parses a class into a ClassModel.

public default byte[]

Returns:

the bytes of the new class
transformClass
(ClassModel
the class model to transform
model
,
ClassTransform
the transform
transform
)

Transform one class file into a new class file according to a ClassTransform.

public default byte[]

Returns:

the bytes of the new class
transformClass
(ClassModel
the class model to transform
model
,
ClassDesc
new class name
newClassName
,
ClassTransform
the transform
transform
)

Transform one class file into a new class file according to a ClassTransform.

public byte[]

Returns:

the bytes of the new class
transformClass
(ClassModel
the class model to transform
model
,
ClassEntry
new class name
newClassName
,
ClassTransform
the transform
transform
)

Transform one class file into a new class file according to a ClassTransform.

public List<VerifyError>

Returns:

a list of verification errors, or an empty list if no error is found
verify
(ClassModel
the class model to verify
model
)

Verify a class file.

public List<VerifyError>

Returns:

a list of verification errors, or an empty list if no error is found
verify
(byte[]
the class file bytes to verify
bytes
)

Verify a class file.

public default List<VerifyError>

Returns:

a list of verification errors, or an empty list if no error is found
verify
(Path
the class file path to verify
path
)

Verify a class file.

public ClassFile

Returns:

a context with altered options from this context
withOptions
(ClassFile.Option...
the desired processing options
options
)

Returns a context with altered options from this context.