@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public static @interface Advice.OnMethodExit
Indicates that this method should be executed before exiting the instrumented method. Any class must declare at most one method with this annotation. The annotated method must be static.
By default, the annotated method is not invoked if the instrumented method terminates exceptionally. This behavior
can be changed by setting the onThrowable()
property to an exception type for which this advice
method should be invoked. By setting the value to Throwable
, the advice method is always invoked.
Advice
,
Advice.Argument
,
Advice.This
,
Advice.Enter
,
Advice.Return
,
Advice.Thrown
Modifier and Type | Optional Element and Description |
---|---|
boolean |
backupArguments
If
true , all arguments of the instrumented method are copied before execution. |
boolean |
inline
Determines if the annotated method should be inlined into the instrumented method or invoked from it.
|
Class<? extends Throwable> |
onThrowable
Indicates a
Throwable super type for which this exit advice is invoked if it was thrown from the instrumented method. |
Class<?> |
repeatOn
Determines if the execution of the instrumented method should be repeated.
|
int |
repeatOnIndex
Indicates that the value to be used for
repeatOn() should be read from an array that is returned by
the advice method, if the assigned property is non-negative. |
Class<? extends Throwable> |
suppress
Indicates that this advice should suppress any
Throwable type being thrown during the advice's execution. |
public abstract Class<?> repeatOn
Determines if the execution of the instrumented method should be repeated. This does not include any enter advice.
When specifying a non-primitive type, this method's return value that is subject to an instanceof
check where
the instrumented method is only executed, if the returned instance is not
an instance of the specified class.
Alternatively, it is possible to specify either Advice.OnDefaultValue
or Advice.OnNonDefaultValue
where the instrumented
method is only repeated if the advice method returns a default or non-default value of the advice method's return type.
It is illegal to specify a primitive type as an argument whereas setting the value to void
indicates that the
instrumented method should never be repeated.
Important: Constructors cannot be repeated.
void
if the instrumented method should never be repeated.public abstract int repeatOnIndex
repeatOn()
should be read from an array that is returned by
the advice method, if the assigned property is non-negative. If the returned array is shorter than the supplied index,
an ArrayIndexOutOfBoundsException
will be thrown, even if suppression is used.public abstract Class<? extends Throwable> onThrowable
Throwable
super type for which this exit advice is invoked if it was thrown from the instrumented method.
If an exception is thrown, it is available via the Advice.Thrown
parameter annotation. If a method returns exceptionally,
any parameter annotated with Advice.Return
is assigned the parameter type's default value.Throwable
for which this exit advice handler is invoked.public abstract boolean backupArguments
If true
, all arguments of the instrumented method are copied before execution. Doing so, parameter reassignments applied
by the instrumented are not effective during the execution of the annotated exit advice.
Disabling this option can cause problems with the translation of stack map frames (meta data that is embedded in a Java class) if these
frames become inconsistent with the original arguments of the instrumented method. In this case, the original arguments are no longer
available to the exit advice such that Byte Buddy must abort the instrumentation with an error. If the instrumented method does not issue
a stack map frame due to a lack of branching instructions, Byte Buddy might not be able to discover such an inconsistency what can cause
a VerifyError
instead of a Byte Buddy-issued exception as those inconsistencies are not discovered.
true
if a backup of all method arguments should be made.public abstract boolean inline
true
if the annotated method should be inlined into the instrumented method.public abstract Class<? extends Throwable> suppress
Throwable
type being thrown during the advice's execution. By default,
any such exception is silently suppressed. Custom behavior can be configured by using Advice.withExceptionHandler(StackManipulation)
.Throwable
to suppress.Advice.withExceptionPrinting()
Copyright © 2014–2024. All rights reserved.