Class CheckMethodAdapter


  • public class CheckMethodAdapter
    extends org.objectweb.asm.MethodVisitor
    A MethodVisitor that checks that its methods are properly used. More precisely this method adapter checks each instruction individually, i.e., each visit method checks some preconditions based only on its arguments - such as the fact that the given opcode is correct for a given visit method. This adapter can also perform some basic data flow checks (more precisely those that can be performed without the full class hierarchy - see BasicVerifier). For instance in a method whose signature is void m (), the invalid instruction IRETURN, or the invalid sequence IADD L2I will be detected if the data flow checks are enabled. These checks are enabled by using the CheckMethodAdapter(int,String,String,MethodVisitor,Map) constructor. They are not performed if any other constructor is used.
    Author:
    Eric Bruneton
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int version
      The class version number.
      • Fields inherited from class org.objectweb.asm.MethodVisitor

        api, mv
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CheckMethodAdapter​(int api, int access, java.lang.String name, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor, java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
      Constructs a new CheckMethodAdapter object.
        CheckMethodAdapter​(int access, java.lang.String name, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor, java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
      Constructs a new CheckMethodAdapter object.
      protected CheckMethodAdapter​(int api, org.objectweb.asm.MethodVisitor methodVisitor, java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
      Constructs a new CheckMethodAdapter object.
        CheckMethodAdapter​(org.objectweb.asm.MethodVisitor methodvisitor)
      Constructs a new CheckMethodAdapter object.
        CheckMethodAdapter​(org.objectweb.asm.MethodVisitor methodVisitor, java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
      Constructs a new CheckMethodAdapter object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void visitAnnotableParameterCount​(int parameterCount, boolean visible)  
      org.objectweb.asm.AnnotationVisitor visitAnnotation​(java.lang.String descriptor, boolean visible)  
      org.objectweb.asm.AnnotationVisitor visitAnnotationDefault()  
      void visitAttribute​(org.objectweb.asm.Attribute attribute)  
      void visitCode()  
      void visitEnd()  
      void visitFieldInsn​(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor)  
      void visitFrame​(int type, int numLocal, java.lang.Object[] local, int numStack, java.lang.Object[] stack)  
      void visitIincInsn​(int varIndex, int increment)  
      void visitInsn​(int opcode)  
      org.objectweb.asm.AnnotationVisitor visitInsnAnnotation​(int typeRef, org.objectweb.asm.TypePath typePath, java.lang.String descriptor, boolean visible)  
      void visitIntInsn​(int opcode, int operand)  
      void visitInvokeDynamicInsn​(java.lang.String name, java.lang.String descriptor, org.objectweb.asm.Handle bootstrapMethodHandle, java.lang.Object... bootstrapMethodArguments)  
      void visitJumpInsn​(int opcode, org.objectweb.asm.Label label)  
      void visitLabel​(org.objectweb.asm.Label label)  
      void visitLdcInsn​(java.lang.Object value)  
      void visitLineNumber​(int line, org.objectweb.asm.Label start)  
      void visitLocalVariable​(java.lang.String name, java.lang.String descriptor, java.lang.String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index)  
      org.objectweb.asm.AnnotationVisitor visitLocalVariableAnnotation​(int typeRef, org.objectweb.asm.TypePath typePath, org.objectweb.asm.Label[] start, org.objectweb.asm.Label[] end, int[] index, java.lang.String descriptor, boolean visible)  
      void visitLookupSwitchInsn​(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels)  
      void visitMaxs​(int maxStack, int maxLocals)  
      void visitMethodInsn​(int opcodeAndSource, java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface)  
      void visitMultiANewArrayInsn​(java.lang.String descriptor, int numDimensions)  
      void visitParameter​(java.lang.String name, int access)  
      org.objectweb.asm.AnnotationVisitor visitParameterAnnotation​(int parameter, java.lang.String descriptor, boolean visible)  
      void visitTableSwitchInsn​(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label... labels)  
      org.objectweb.asm.AnnotationVisitor visitTryCatchAnnotation​(int typeRef, org.objectweb.asm.TypePath typePath, java.lang.String descriptor, boolean visible)  
      void visitTryCatchBlock​(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, java.lang.String type)  
      org.objectweb.asm.AnnotationVisitor visitTypeAnnotation​(int typeRef, org.objectweb.asm.TypePath typePath, java.lang.String descriptor, boolean visible)  
      void visitTypeInsn​(int opcode, java.lang.String type)  
      void visitVarInsn​(int opcode, int varIndex)  
      • Methods inherited from class org.objectweb.asm.MethodVisitor

        getDelegate, visitMethodInsn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • version

        public int version
        The class version number.
    • Constructor Detail

      • CheckMethodAdapter

        public CheckMethodAdapter​(org.objectweb.asm.MethodVisitor methodVisitor,
                                  java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
        Constructs a new CheckMethodAdapter object. This method adapter will not perform any data flow check (see CheckMethodAdapter(int,String,String,MethodVisitor,Map)). Subclasses must not use this constructor. Instead, they must use the CheckMethodAdapter(int, MethodVisitor, Map) version.
        Parameters:
        methodVisitor - the method visitor to which this adapter must delegate calls.
        labelInsnIndices - the index of the instruction designated by each visited label so far (in other methods). This map is updated with the labels from the visited method.
        Throws:
        java.lang.IllegalStateException - If a subclass calls this constructor.
      • CheckMethodAdapter

        protected CheckMethodAdapter​(int api,
                                     org.objectweb.asm.MethodVisitor methodVisitor,
                                     java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
        Constructs a new CheckMethodAdapter object. This method adapter will not perform any data flow check (see CheckMethodAdapter(int,String,String,MethodVisitor,Map)).
        Parameters:
        api - the ASM API version implemented by this CheckMethodAdapter. Must be one of the ASMx values in Opcodes.
        methodVisitor - the method visitor to which this adapter must delegate calls.
        labelInsnIndices - the index of the instruction designated by each visited label so far (in other methods). This map is updated with the labels from the visited method.
      • CheckMethodAdapter

        public CheckMethodAdapter​(int access,
                                  java.lang.String name,
                                  java.lang.String descriptor,
                                  org.objectweb.asm.MethodVisitor methodVisitor,
                                  java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
        Constructs a new CheckMethodAdapter object. This method adapter will perform basic data flow checks. For instance in a method whose signature is void m (), the invalid instruction IRETURN, or the invalid sequence IADD L2I will be detected. Subclasses must not use this constructor. Instead, they must use the CheckMethodAdapter(int,int,String,String,MethodVisitor,Map) version.
        Parameters:
        access - the method's access flags.
        name - the method's name.
        descriptor - the method's descriptor (see Type).
        methodVisitor - the method visitor to which this adapter must delegate calls.
        labelInsnIndices - the index of the instruction designated by each visited label so far (in other methods). This map is updated with the labels from the visited method.
      • CheckMethodAdapter

        protected CheckMethodAdapter​(int api,
                                     int access,
                                     java.lang.String name,
                                     java.lang.String descriptor,
                                     org.objectweb.asm.MethodVisitor methodVisitor,
                                     java.util.Map<org.objectweb.asm.Label,​java.lang.Integer> labelInsnIndices)
        Constructs a new CheckMethodAdapter object. This method adapter will perform basic data flow checks. For instance in a method whose signature is void m (), the invalid instruction IRETURN, or the invalid sequence IADD L2I will be detected.
        Parameters:
        api - the ASM API version implemented by this CheckMethodAdapter. Must be one of the ASMx values in Opcodes.
        access - the method's access flags.
        name - the method's name.
        descriptor - the method's descriptor (see Type).
        methodVisitor - the method visitor to which this adapter must delegate calls.
        labelInsnIndices - the index of the instruction designated by each visited label so far (in other methods). This map is updated with the labels from the visited method.
    • Method Detail

      • visitParameter

        public void visitParameter​(java.lang.String name,
                                   int access)
        Overrides:
        visitParameter in class org.objectweb.asm.MethodVisitor
      • visitAnnotation

        public org.objectweb.asm.AnnotationVisitor visitAnnotation​(java.lang.String descriptor,
                                                                   boolean visible)
        Overrides:
        visitAnnotation in class org.objectweb.asm.MethodVisitor
      • visitTypeAnnotation

        public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation​(int typeRef,
                                                                       org.objectweb.asm.TypePath typePath,
                                                                       java.lang.String descriptor,
                                                                       boolean visible)
        Overrides:
        visitTypeAnnotation in class org.objectweb.asm.MethodVisitor
      • visitAnnotationDefault

        public org.objectweb.asm.AnnotationVisitor visitAnnotationDefault()
        Overrides:
        visitAnnotationDefault in class org.objectweb.asm.MethodVisitor
      • visitAnnotableParameterCount

        public void visitAnnotableParameterCount​(int parameterCount,
                                                 boolean visible)
        Overrides:
        visitAnnotableParameterCount in class org.objectweb.asm.MethodVisitor
      • visitParameterAnnotation

        public org.objectweb.asm.AnnotationVisitor visitParameterAnnotation​(int parameter,
                                                                            java.lang.String descriptor,
                                                                            boolean visible)
        Overrides:
        visitParameterAnnotation in class org.objectweb.asm.MethodVisitor
      • visitAttribute

        public void visitAttribute​(org.objectweb.asm.Attribute attribute)
        Overrides:
        visitAttribute in class org.objectweb.asm.MethodVisitor
      • visitCode

        public void visitCode()
        Overrides:
        visitCode in class org.objectweb.asm.MethodVisitor
      • visitFrame

        public void visitFrame​(int type,
                               int numLocal,
                               java.lang.Object[] local,
                               int numStack,
                               java.lang.Object[] stack)
        Overrides:
        visitFrame in class org.objectweb.asm.MethodVisitor
      • visitInsn

        public void visitInsn​(int opcode)
        Overrides:
        visitInsn in class org.objectweb.asm.MethodVisitor
      • visitIntInsn

        public void visitIntInsn​(int opcode,
                                 int operand)
        Overrides:
        visitIntInsn in class org.objectweb.asm.MethodVisitor
      • visitVarInsn

        public void visitVarInsn​(int opcode,
                                 int varIndex)
        Overrides:
        visitVarInsn in class org.objectweb.asm.MethodVisitor
      • visitTypeInsn

        public void visitTypeInsn​(int opcode,
                                  java.lang.String type)
        Overrides:
        visitTypeInsn in class org.objectweb.asm.MethodVisitor
      • visitFieldInsn

        public void visitFieldInsn​(int opcode,
                                   java.lang.String owner,
                                   java.lang.String name,
                                   java.lang.String descriptor)
        Overrides:
        visitFieldInsn in class org.objectweb.asm.MethodVisitor
      • visitMethodInsn

        public void visitMethodInsn​(int opcodeAndSource,
                                    java.lang.String owner,
                                    java.lang.String name,
                                    java.lang.String descriptor,
                                    boolean isInterface)
        Overrides:
        visitMethodInsn in class org.objectweb.asm.MethodVisitor
      • visitInvokeDynamicInsn

        public void visitInvokeDynamicInsn​(java.lang.String name,
                                           java.lang.String descriptor,
                                           org.objectweb.asm.Handle bootstrapMethodHandle,
                                           java.lang.Object... bootstrapMethodArguments)
        Overrides:
        visitInvokeDynamicInsn in class org.objectweb.asm.MethodVisitor
      • visitJumpInsn

        public void visitJumpInsn​(int opcode,
                                  org.objectweb.asm.Label label)
        Overrides:
        visitJumpInsn in class org.objectweb.asm.MethodVisitor
      • visitLabel

        public void visitLabel​(org.objectweb.asm.Label label)
        Overrides:
        visitLabel in class org.objectweb.asm.MethodVisitor
      • visitLdcInsn

        public void visitLdcInsn​(java.lang.Object value)
        Overrides:
        visitLdcInsn in class org.objectweb.asm.MethodVisitor
      • visitIincInsn

        public void visitIincInsn​(int varIndex,
                                  int increment)
        Overrides:
        visitIincInsn in class org.objectweb.asm.MethodVisitor
      • visitTableSwitchInsn

        public void visitTableSwitchInsn​(int min,
                                         int max,
                                         org.objectweb.asm.Label dflt,
                                         org.objectweb.asm.Label... labels)
        Overrides:
        visitTableSwitchInsn in class org.objectweb.asm.MethodVisitor
      • visitLookupSwitchInsn

        public void visitLookupSwitchInsn​(org.objectweb.asm.Label dflt,
                                          int[] keys,
                                          org.objectweb.asm.Label[] labels)
        Overrides:
        visitLookupSwitchInsn in class org.objectweb.asm.MethodVisitor
      • visitMultiANewArrayInsn

        public void visitMultiANewArrayInsn​(java.lang.String descriptor,
                                            int numDimensions)
        Overrides:
        visitMultiANewArrayInsn in class org.objectweb.asm.MethodVisitor
      • visitInsnAnnotation

        public org.objectweb.asm.AnnotationVisitor visitInsnAnnotation​(int typeRef,
                                                                       org.objectweb.asm.TypePath typePath,
                                                                       java.lang.String descriptor,
                                                                       boolean visible)
        Overrides:
        visitInsnAnnotation in class org.objectweb.asm.MethodVisitor
      • visitTryCatchBlock

        public void visitTryCatchBlock​(org.objectweb.asm.Label start,
                                       org.objectweb.asm.Label end,
                                       org.objectweb.asm.Label handler,
                                       java.lang.String type)
        Overrides:
        visitTryCatchBlock in class org.objectweb.asm.MethodVisitor
      • visitTryCatchAnnotation

        public org.objectweb.asm.AnnotationVisitor visitTryCatchAnnotation​(int typeRef,
                                                                           org.objectweb.asm.TypePath typePath,
                                                                           java.lang.String descriptor,
                                                                           boolean visible)
        Overrides:
        visitTryCatchAnnotation in class org.objectweb.asm.MethodVisitor
      • visitLocalVariable

        public void visitLocalVariable​(java.lang.String name,
                                       java.lang.String descriptor,
                                       java.lang.String signature,
                                       org.objectweb.asm.Label start,
                                       org.objectweb.asm.Label end,
                                       int index)
        Overrides:
        visitLocalVariable in class org.objectweb.asm.MethodVisitor
      • visitLocalVariableAnnotation

        public org.objectweb.asm.AnnotationVisitor visitLocalVariableAnnotation​(int typeRef,
                                                                                org.objectweb.asm.TypePath typePath,
                                                                                org.objectweb.asm.Label[] start,
                                                                                org.objectweb.asm.Label[] end,
                                                                                int[] index,
                                                                                java.lang.String descriptor,
                                                                                boolean visible)
        Overrides:
        visitLocalVariableAnnotation in class org.objectweb.asm.MethodVisitor
      • visitLineNumber

        public void visitLineNumber​(int line,
                                    org.objectweb.asm.Label start)
        Overrides:
        visitLineNumber in class org.objectweb.asm.MethodVisitor
      • visitMaxs

        public void visitMaxs​(int maxStack,
                              int maxLocals)
        Overrides:
        visitMaxs in class org.objectweb.asm.MethodVisitor
      • visitEnd

        public void visitEnd()
        Overrides:
        visitEnd in class org.objectweb.asm.MethodVisitor