Annotation Type Advice.OnMethodExit
- Enclosing class:
Advice
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.
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionboolean
Iftrue
, all arguments of the instrumented method are copied before execution.boolean
Determines if the annotated method should be inlined into the instrumented method or invoked from it.Indicates aThrowable
super type for which this exit advice is invoked if it was thrown from the instrumented method.Class
<?> Determines if the execution of the instrumented method should be repeated.int
Indicates that the value to be used forrepeatOn()
should be read from an array that is returned by the advice method, if the assigned property is non-negative.Indicates that this advice should suppress anyThrowable
type being thrown during the advice's execution.
-
Element Details
-
repeatOn
Class<?> repeatOnDetermines 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 isnot
an instance of the specified class. Alternatively, it is possible to specify eitherAdvice.OnDefaultValue
orAdvice.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 tovoid
indicates that the instrumented method should never be repeated.Important: Constructors cannot be repeated.
- Returns:
- A value defining what return values of the advice method indicate that the instrumented method
should be repeated or
void
if the instrumented method should never be repeated.
- Default:
void.class
-
repeatOnIndex
int repeatOnIndexIndicates that the value to be used forrepeatOn()
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, anArrayIndexOutOfBoundsException
will be thrown, even if suppression is used.- Returns:
- The array index for the value to be considered for repeating a method, or a negative value for using the returned value.
- Default:
-1
-
onThrowable
Indicates aThrowable
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 theAdvice.Thrown
parameter annotation. If a method returns exceptionally, any parameter annotated withAdvice.Return
is assigned the parameter type's default value.- Returns:
- The type of
Throwable
for which this exit advice handler is invoked.
- Default:
net.bytebuddy.asm.Advice.NoExceptionHandler.class
-
backupArguments
boolean backupArgumentsIf
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.- Returns:
true
if a backup of all method arguments should be made.
- Default:
true
-
inline
boolean inlineDetermines if the annotated method should be inlined into the instrumented method or invoked from it. When a method is inlined, its byte code is copied into the body of the target method. this makes it is possible to execute code with the visibility privileges of the instrumented method while loosing the privileges of the declared method methods. When a method is not inlined, it is invoked similarly to a common Java method call. Note that it is not possible to set breakpoints within a method when it is inlined as no debugging information is copied from the advice method into the instrumented method.- Returns:
true
if the annotated method should be inlined into the instrumented method.
- Default:
true
-
suppress
Indicates that this advice should suppress anyThrowable
type being thrown during the advice's execution. By default, any such exception is silently suppressed. Custom behavior can be configured by usingAdvice.withExceptionHandler(StackManipulation)
.- Returns:
- The type of
Throwable
to suppress. - See Also:
- Default:
net.bytebuddy.asm.Advice.NoExceptionHandler.class
-