ASM 5.0.3 With Java 1.8 incorrect maxStack with Java.lang.VerifyError: Operand stack overflow

后端 未结 1 1187
独厮守ぢ
独厮守ぢ 2021-01-25 09:28

Using ASM 5.0.3 (with Java 1.8.0_65 & Tomcat 8.0.30) , Visiting one of the JSP (date.jsp) Method - _JSP(_jspService) , getting below exception

javax.servlet.         


        
相关标签:
1条回答
  • 2021-01-25 09:53

    I found the solution to resolve such kind of VerifyError with java 1.7 and 1.8

    In the transform() method of MyClassFileTransformer , i replaced the line

    ClassWriter classWriter = new ClassWriter(classReader, writerFlag); with new line ClassWriter classWriter = new ByteCodeWriter(classReader, loader, writerFlag);

    ByteCodeWriter.java

    `

    import org.objectweb.asm.ClassReader;
    import org.objectweb.asm.ClassWriter;
    
    public class ByteCodeWriter extends ClassWriter
    {
      static final String OBJECT_REPRESENTATION = "java/lang/Object";
      ClassLoader classLoader;
    
      public ByteCodeWriter(ClassReader classReader, ClassLoader loader, int writerFlag)
      {
        super(classReader, writerFlag);
        this.classLoader = loader;
      }
    
      protected String getCommonSuperClass(String className1, String className2)
      {
        Class class1;
        Class class2;
        try
        {
          class1 = Class.forName(className1.replace('/', '.'), false, this.classLoader);
          class2 = Class.forName(className2.replace('/', '.'), false, this.classLoader);
        }
        catch (Exception th) {
          throw new RuntimeException(th.getMessage());
        }
    
        if (class1.isAssignableFrom(class2)) {
          return className1;
        }
        if (class2.isAssignableFrom(class1)) {
          return className2;
        }
    
        if ((class1.isInterface()) || (class2.isInterface())) {
          return "java/lang/Object";
        }
    
        do {
          class1 = class1.getSuperclass();
        }
        while (!(class1.isAssignableFrom(class2)));
        return class1.getName().replace('.', '/');
      }
    }`
    

    Basically I extend ClassWriter class and override the method getCommonSuperClass

    Error while instrumenting class files (asm.ClassWriter.getCommonSuperClass) helped me to resolve the issue.

    But i do not know, what is the necessity to override getCommonSuperClass.

    0 讨论(0)
提交回复
热议问题