Class ExceptionMethod

  • All Implemented Interfaces:
    InstrumentedType.Prepareable, ByteCodeAppender, Implementation

    public class ExceptionMethod
    extends java.lang.Object
    implements Implementation, ByteCodeAppender
    This implementation causes a Throwable to be thrown when the instrumented method is invoked. Be aware that the Java Virtual machine does not care about exception declarations and will throw any Throwable from any method even if the method does not declared a checked exception.
    • Constructor Detail

      • ExceptionMethod

        public ExceptionMethod​(TypeDescription throwableType,
                               ExceptionMethod.ConstructionDelegate constructionDelegate)
        Creates a new instance of an implementation for throwing throwables.
        Parameters:
        throwableType - The type of the exception to be thrown.
        constructionDelegate - A delegate that is responsible for calling the isThrowable's constructor.
    • Method Detail

      • throwing

        public static Implementation throwing​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
        Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a default constructor which is visible from the instrumented type.
        Parameters:
        exceptionType - The type of the isThrowable.
        Returns:
        An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
      • throwing

        public static Implementation throwing​(TypeDescription exceptionType)
        Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a default constructor which is visible from the instrumented type.
        Parameters:
        exceptionType - The type of the isThrowable.
        Returns:
        An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
      • throwing

        public static Implementation throwing​(java.lang.Class<? extends java.lang.Throwable> exceptionType,
                                              java.lang.String message)
        Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a constructor that takes a single String as its argument.
        Parameters:
        exceptionType - The type of the isThrowable.
        message - The string that is handed to the constructor. Usually an exception message.
        Returns:
        An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
      • throwing

        public static Implementation throwing​(TypeDescription exceptionType,
                                              java.lang.String message)
        Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a constructor that takes a single String as its argument.
        Parameters:
        exceptionType - The type of the isThrowable.
        message - The string that is handed to the constructor. Usually an exception message.
        Returns:
        An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
      • appender

        public ByteCodeAppender appender​(Implementation.Target implementationTarget)
        Description copied from interface: Implementation
        Creates a byte code appender that determines the implementation of the instrumented type's methods.
        Specified by:
        appender in interface Implementation
        Parameters:
        implementationTarget - The target of the current implementation.
        Returns:
        A byte code appender for implementing methods delegated to this implementation. This byte code appender is also responsible for handling methods that were added by this implementation on the call to InstrumentedType.Prepareable.prepare(InstrumentedType).
      • apply

        public ByteCodeAppender.Size apply​(org.objectweb.asm.MethodVisitor methodVisitor,
                                           Implementation.Context implementationContext,
                                           MethodDescription instrumentedMethod)
        Description copied from interface: ByteCodeAppender
        Applies this byte code appender to a type creation process.
        Specified by:
        apply in interface ByteCodeAppender
        Parameters:
        methodVisitor - The method visitor to which the byte code appender writes its code to.
        implementationContext - The implementation context of the current type creation process.
        instrumentedMethod - The method that is the target of the instrumentation.
        Returns:
        The required size for the applied byte code to run.