StackWalker.StackFrame (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.lang, class: StackWalker, interface: StackFrame
Keywords: java.lang.StackWalker.StackFrame interface

# Interface StackWalker.StackFrame

Enclosing class:
  `StackWalker`

public static interface StackWalker.StackFrame
A `StackFrame` object represents a method invocation returned by `StackWalker`.

Stack walker options configure the stack frame information obtained by a `StackWalker`. If the stack walker is configured with `DROP_METHOD_INFO` option, method information such as the method name, the line number, the bytecode index, etc will be dropped. If the stack walker is configured with `RETAIN_CLASS_REFERENCE` option, the `Class` object will be retained for access.

See Java Virtual Machine Specification:
  2.6 Frames
Since:
  9

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getByteCodeIndex()`
  Returns the index to the code array of the `Code` attribute containing the execution point represented by this stack frame.
  `String`
  `getClassName()`
  Returns the binary name of the declaring class of the method represented by this stack frame.
  `Class<?>`
  `getDeclaringClass()`
  Returns the declaring `Class` for the method represented by this stack frame.
  `default String`
  `getDescriptor()`
  Returns the descriptor of the method represented by this stack frame as defined by The Java Virtual Machine Specification.
  `String`
  `getFileName()`
  Returns the name of the source file containing the execution point represented by this stack frame.
  `int`
  `getLineNumber()`
  Returns the line number of the source line containing the execution point represented by this stack frame.
  `String`
  `getMethodName()`
  Returns the name of the method represented by this stack frame.
  `default MethodType`
  `getMethodType()`
  Returns the `MethodType` representing the parameter types and the return type for the method represented by this stack frame.
  `boolean`
  `isNativeMethod()`
  Returns `true` if the method containing the execution point represented by this stack frame is a native method.
  `StackTraceElement`
  `toStackTraceElement()`
  Returns `StackTraceElement` for this stack frame.

- ## Method Details

  - ### getClassName

    String getClassName()
    Returns the binary name of the declaring class of the method represented by this stack frame.
    Returns:
      the binary name of the declaring class of the method represented by this stack frame
    See Java Language Specification:
      13.1 The Form of a Binary

  - ### getMethodName

    String getMethodName()
    Returns the name of the method represented by this stack frame.
    Returns:
      the name of the method represented by this stack frame
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option

  - ### getDeclaringClass

    Class<?> getDeclaringClass()
    Returns the declaring `Class` for the method represented by this stack frame.
    Returns:
      the declaring `Class` for the method represented by this stack frame
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured without `RETAIN_CLASS_REFERENCE` option

  - ### getMethodType

    default MethodType getMethodType()
    Returns the `MethodType` representing the parameter types and the return type for the method represented by this stack frame.
    Implementation Requirements:
      The default implementation throws `UnsupportedOperationException`.
    Returns:
      the `MethodType` of the method represented by this stack frame
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option or without `RETAIN_CLASS_REFERENCE` option
    Since:
      10

  - ### getDescriptor

    default String getDescriptor()
    Returns the descriptor of the method represented by this stack frame as defined by The Java Virtual Machine Specification.
    Implementation Requirements:
      The default implementation throws `UnsupportedOperationException`.
    Returns:
      the descriptor of the method represented by this stack frame
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option
    See Java Virtual Machine Specification:
      4.3.3 Method Descriptors
    Since:
      10
    See Also:
      - `MethodType.fromMethodDescriptorString(String, ClassLoader)`
      - `MethodType.toMethodDescriptorString()`

  - ### getByteCodeIndex

    int getByteCodeIndex()
    Returns the index to the code array of the `Code` attribute containing the execution point represented by this stack frame. The code array gives the actual bytes of Java Virtual Machine code that implement the method.
    Returns:
      the index to the code array of the `Code` attribute containing the execution point represented by this stack frame, or a negative number if the method is native.
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option
    See Java Virtual Machine Specification:
      4.7.3 The `Code` Attribute

  - ### getFileName

    String getFileName()
    Returns the name of the source file containing the execution point represented by this stack frame. Generally, this corresponds to the `SourceFile` attribute of the relevant `class` file as defined by The Java Virtual Machine Specification. In some systems, the name may refer to some source code unit other than a file, such as an entry in a source repository.
    Returns:
      the name of the file containing the execution point represented by this stack frame, or `null` if this information is unavailable.
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option
    See Java Virtual Machine Specification:
      4.7.10 The `SourceFile` Attribute

  - ### getLineNumber

    int getLineNumber()
    Returns the line number of the source line containing the execution point represented by this stack frame. Generally, this is derived from the `LineNumberTable` attribute of the relevant `class` file as defined by The Java Virtual Machine Specification.
    Returns:
      the line number of the source line containing the execution point represented by this stack frame, or a negative number if this information is unavailable.
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option
    See Java Virtual Machine Specification:
      4.7.12 The `LineNumberTable` Attribute

  - ### isNativeMethod

    boolean isNativeMethod()
    Returns `true` if the method containing the execution point represented by this stack frame is a native method.
    Returns:
      `true` if the method containing the execution point represented by this stack frame is a native method
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option

  - ### toStackTraceElement

    StackTraceElement toStackTraceElement()
    Returns `StackTraceElement` for this stack frame.
    Returns:
      `StackTraceElement` for this stack frame
    Throws:
      `UnsupportedOperationException` - if the `StackWalker` is configured with `DROP_METHOD_INFO` option