# Interface CodeAttribute

All Superinterfaces:
  `Attribute<CodeAttribute>, AttributedElement, ClassFileElement, CodeModel, CompoundElement<CodeElement>, Iterable<CodeElement>, MethodElement`

public sealed interface CodeAttribute extends Attribute<CodeAttribute>, CodeModel
Models the `Code` attribute (JVMS §4.7.3), which contains the bytecode of this method.

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

This attribute was introduced in the Java Platform version 1.0.2, major version 45.

API Note:
  `CodeAttribute` models properties of a `Code` attribute read from `class` files. General `class` file transformation should process and traverse a `CodeModel` in the traversal of a `MethodModel`, to support transformation of `Code` attributes currently being built.
See Java Virtual Machine Specification:
  4.7.3 The `Code` Attribute
Since:
  24
See Also:
  - `Attributes.code()`
  - `CodeModel`

## Method Summary

Modifier and Type
Method
Description
`byte[]`
`codeArray()`
Returns the bytes (bytecode) of the code array.
`int`
`codeLength()`
Returns The length of the code array in bytes.
`int`
`labelToBci(Label label)`
Returns the position of the `label` in the `codeArray`.
`int`
`maxLocals()`
Returns the maximum size of the local variable table.
`int`
`maxStack()`
Returns the maximum size of the operand stack.

### Methods declared in interface Attribute

`attributeMapper, attributeName`
Modifier and Type
Method
Description
`AttributeMapper<CodeAttribute>`
`attributeMapper()`
Returns the `AttributeMapper` associated with this attribute.
`Utf8Entry`
`attributeName()`
Returns the name of the attribute.

### Methods declared in interface AttributedElement

`attributes, findAttribute, findAttributes`
Modifier and Type
Method
Description
`List<Attribute<?>>`
`attributes()`
Returns the attributes of this structure.
`default <T extends Attribute<T>>
Optional<T>`
`findAttribute(AttributeMapper<T> attr)`
Finds an attribute by name.
`default <T extends Attribute<T>>
List<T>`
`findAttributes(AttributeMapper<T> attr)`
Finds attributes by name.

### Methods declared in interface CodeModel

`exceptionHandlers, parent`
Modifier and Type
Method
Description
`List<ExceptionCatch>`
`exceptionHandlers()`
Returns the exception table of the method.
`Optional<MethodModel>`
`parent()`
Returns the enclosing method, if known.

### Methods declared in interface CompoundElement

`elementList, elementStream, forEach, iterator, toDebugString`
Modifier and Type
Method
Description
`default List<CodeElement>`
`elementList()`
Returns a `List` containing all member elements in this compound element.
`default Stream<CodeElement>`
`elementStream()`
Returns a `Stream` containing all member elements in this compound element.
`void`
`forEach(Consumer<? super CodeElement> consumer)`
Invokes the provided handler with each member element in this compound element.
`default Iterator<CodeElement>`
`iterator()`
Returns an `Iterator` describing all member elements in this compound element.
`default String`
`toDebugString()`
Returns a text representation of the compound element and its contents for debugging purposes.

### Methods declared in interface Iterable

`spliterator`
Modifier and Type
Method
Description
`default Spliterator<CodeElement>`
`spliterator()`
Creates a `Spliterator` over the elements described by this `Iterable`.

## Method Details

### maxLocals

int maxLocals()
Returns the maximum size of the local variable table.

Returns:
  the maximum size of the local variable table

### maxStack

int maxStack()
Returns the maximum size of the operand stack.

Returns:
  the maximum size of the operand stack

### codeLength

int codeLength()
Returns The length of the code array in bytes.

Returns:
  The length of the code array in bytes

### codeArray

byte[] codeArray()
Returns the bytes (bytecode) of the code array.

Returns:
  the bytes (bytecode) of the code array

### labelToBci

int labelToBci(Label label)
Returns the position of the `label` in the `codeArray`. The label represents a cursor pointing at immediately before the returned index into the `code` array.

Parameters:
  `label` - a marker for a position within this `CodeAttribute`
Returns:
  the position of the `label` in the `codeArray`
Throws:
  `IllegalArgumentException` - if the `label` is not from this attribute