Annotation Type Advice.OnMethodExit
-
@Documented @Retention(RUNTIME) @Target(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 toThrowable
, the advice method is always invoked.- See Also:
Advice
,Advice.Argument
,Advice.This
,Advice.Enter
,Advice.Return
,Advice.Thrown
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
backupArguments
Iftrue
, 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.java.lang.Class<? extends java.lang.Throwable>
onThrowable
Indicates aThrowable
super type for which this exit advice is invoked if it was thrown from the instrumented method.java.lang.Class<?>
repeatOn
Determines if the execution of the instrumented method should be repeated.java.lang.Class<? extends java.lang.Throwable>
suppress
Indicates that this advice should suppress anyThrowable
type being thrown during the advice's execution.
-
-
-
Element Detail
-
repeatOn
java.lang.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 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
-
-
-
onThrowable
java.lang.Class<? extends java.lang.Throwable> 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 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.- Returns:
true
if a backup of all method arguments should be made.
- Default:
- true
-
-
-
inline
boolean inline
Determines 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
java.lang.Class<? extends java.lang.Throwable> 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:
Advice.withExceptionPrinting()
- Default:
- net.bytebuddy.asm.Advice.NoExceptionHandler.class
-
-