Class 
Use 
SUMMARY: NESTED | FIELD | CONSTR | METHOD      DETAIL: FIELD | CONSTR | METHOD
FlexDoc/Javadoc 2.0
Demo Java Doc

java.base / java.lang
Class StackWalker
java.lang.Object
  java.lang.StackWalker

public final class StackWalker
extends Object
A stack walker.

The walk method opens a sequential stream of StackFrames for the current thread and then applies the given function to walk the StackFrame stream. The stream reports stack frame elements in order, from the top most frame that represents the execution point at which the stack was generated to the bottom most frame. The StackFrame stream is closed when the walk method returns. If an attempt is made to reuse the closed stream, IllegalStateException will be thrown.

The stack walking options of a StackWalker determines the information of StackFrame objects to be returned. By default, stack frames of the reflection API and implementation classes are hidden and StackFrames have the class name and method name available but not the Class reference.

StackWalker is thread-safe. Multiple threads can share a single StackWalker object to traverse its own stack. A permission check is performed when a StackWalker is created, according to the options it requests. No further permission check is done at stack walking time.

Since:
9

Nested Class Summary
static enum
Stack walker option to configure the stack frame information obtained by a StackWalker.
static interface
A StackFrame object represents a method invocation returned by StackWalker.
Method Summary
void
Performs the given action on each element of StackFrame stream of the current thread, traversing from the top frame of the stack, which is the method calling this forEach method.
Gets the Class object of the caller who invoked the method that invoked getCallerClass.
Returns a StackWalker instance.
Returns a StackWalker instance with the given options specifying the stack frame information it can access.
getInstance(Set<StackWalker.Option> options, int estimateDepth)
Returns a StackWalker instance with the given options specifying the stack frame information it can access.
Returns a StackWalker instance with the given option specifying the stack frame information it can access.
<TT
walk(Function<? super Stream<StackWalker.StackFrame>,? extends T> function)
Applies the given function to the stream of StackFrames for the current thread, traversing from the top frame of the stack, which is the method calling this walk method.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Detail
getInstance
public static StackWalker getInstance
()
Returns a StackWalker instance.

This StackWalker is configured to skip all hidden frames and no class reference is retained.

Returns:
a StackWalker configured to skip all hidden frames and no class reference is retained.

getInstance
public static StackWalker getInstance
Returns a StackWalker instance with the given option specifying the stack frame information it can access.

If a security manager is present and the given option is Option.RETAIN_CLASS_REFERENCE, it calls its checkPermission method for RuntimePermission("getStackWalkerWithClassReference").

Parameters:
option - stack walking option
Returns:
a StackWalker configured with the given option
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access.

getInstance
public static StackWalker getInstance
Returns a StackWalker instance with the given options specifying the stack frame information it can access. If the given options is empty, this StackWalker is configured to skip all hidden frames and no class reference is retained.

If a security manager is present and the given options contains Option.RETAIN_CLASS_REFERENCE, it calls its checkPermission method for RuntimePermission("getStackWalkerWithClassReference").

Parameters:
options - stack walking option
Returns:
a StackWalker configured with the given options
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access.

getInstance
public static StackWalker getInstance
(Set<StackWalker.Option> options,
 int estimateDepth)
Returns a StackWalker instance with the given options specifying the stack frame information it can access. If the given options is empty, this StackWalker is configured to skip all hidden frames and no class reference is retained.

If a security manager is present and the given options contains Option.RETAIN_CLASS_REFERENCE, it calls its checkPermission method for RuntimePermission("getStackWalkerWithClassReference").

The estimateDepth specifies the estimate number of stack frames this StackWalker will traverse that the StackWalker could use as a hint for the buffer size.

Parameters:
options - stack walking options
estimateDepth - Estimate number of stack frames to be traversed.
Returns:
a StackWalker configured with the given options
Throws:
IllegalArgumentException - if estimateDepth <= 0
SecurityException - if a security manager exists and its checkPermission method denies access.

walk
public <T> T walk
(Function<? super Stream<StackWalker.StackFrame>,? extends T> function)
Applies the given function to the stream of StackFrames for the current thread, traversing from the top frame of the stack, which is the method calling this walk method.

The StackFrame stream will be closed when this method returns. When a closed Stream<StackFrame> object is reused, IllegalStateException will be thrown.

Implementation Note:
The implementation stabilizes the stack by anchoring a frame specific to the stack walking and ensures that the stack walking is performed above the anchored frame. When the stream object is closed or being reused, IllegalStateException will be thrown.
Type Parameters:
T - The type of the result of applying the function to the stream of stack frame.
Parameters:
function - a function that takes a stream of stack frames and returns a result.
Returns:
the result of applying the function to the stream of stack frame.

forEach
public void forEach
(Consumer<? super StackWalker.StackFrame> action)
Performs the given action on each element of StackFrame stream of the current thread, traversing from the top frame of the stack, which is the method calling this forEach method.

This method is equivalent to calling

walk(s -> { s.forEach(action); return null; });
Parameters:
action - an action to be performed on each StackFrame of the stack of the current thread

getCallerClass
public Class<?> getCallerClass
()
Gets the Class object of the caller who invoked the method that invoked getCallerClass.

This method filters reflection frames, MethodHandle, and hidden frames regardless of the SHOW_REFLECT_FRAMES and SHOW_HIDDEN_FRAMES options this StackWalker has been configured with.

This method should be called when a caller frame is present. If it is called from the bottom most frame on the stack, IllegalCallerException will be thrown.

This method throws UnsupportedOperationException if this StackWalker is not configured with the RETAIN_CLASS_REFERENCE option.

Returns:
Class object of the caller's caller invoking this method.
Throws:
UnsupportedOperationException - if this StackWalker is not configured with Option.RETAIN_CLASS_REFERENCE.
IllegalCallerException - if there is no caller frame, i.e. when this getCallerClass method is called from a method which is the last frame on the stack.

 Class 
Use 
SUMMARY: NESTED | FIELD | CONSTR | METHOD      DETAIL: FIELD | CONSTR | METHOD
FlexDoc/Javadoc 2.0
Demo Java Doc

Java API documentation generated with FlexDoc/Javadoc 2.0 using JavadocClassic 3.0 template set.
FlexDoc/Javadoc is a template-driven programming tool for rapid development of any Javadoc-based Java API documentation generators (i.e. doclets). If you need to customize your Javadoc without writing a full-blown doclet from scratch, FlexDoc/Javadoc may be the only tool able to help you! Find out more at www.flexdoc.xyz