title: Creating MethodNode fails with IllegalStateException
body: <p>I want to get the <code>MethodNode</code> of <code>main()</code> function </p>
  
  <pre><code>public class TestMethodNode {      
      public void main() {            
      }
  }
  </code></pre>
  
  <p>so i tried this</p>
  
  <pre><code>import org.objectweb.asm.ClassReader;
  import org.objectweb.asm.ClassVisitor;
  import org.objectweb.asm.ClassWriter;
  import org.objectweb.asm.MethodVisitor;
  import org.objectweb.asm.tree.MethodNode;   
  import static org.objectweb.asm.Opcodes.ASM7; 
  import java.io.IOException;    
  
  public class Instrumentation {
      public byte[] editFunction(String className) throws IOException {    
          byte[] modifiedClass = null;    
          try {    
              ClassReader classReader = new ClassReader(className);
              ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES);
              ClassVisitor classAdapter = new ClassVisitor(ASM7, classWriter) {    
                  public MethodVisitor visitMethod(
                          int access,
                          String name,
                          String desc,
                          String signature,
                          String[] exceptions) {    
                      if (name.equals("main")) {
                          final MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
                          MethodNode methodNode = new MethodNode(access, name, desc, signature, exceptions) {
                              public void visitEnd() {
                                  // transform / analyze method here
                                  accept(methodVisitor);
                              }
                          };    
                          return methodNode;
                      }  else {  
                          return super.visitMethod(access, name, desc, signature, exceptions);
                      }
                  }
              };    
              classReader.accept(classAdapter, 0);
              modifiedClass = classWriter.toByteArray();  
          } catch (IOException ex) {    
              throw ex;
          }    
          return modifiedClass;
      }
  }
  </code></pre>
  
  <p>and got <code>IllegalStateException</code> from .../asm/tree/MethodNode.java while creating <code>MethodNode</code></p>
  
  <pre><code>  public MethodNode(
        final int access,
        final String name,
        final String descriptor,
        final String signature,
        final String[] exceptions) {
      this(Opcodes.ASM7, access, name, descriptor, signature, exceptions);
      if (getClass() != MethodNode.class) {
        throw new IllegalStateException();
      }
    }
  </code></pre>
  
  <p>What i'm doing wrong? (I don't want to hack Minecraft, i am researching and trying to manipulate callstacks wich involve lambda expressions and nested / inner classes for a workflow engine that uses bytecode manipulation at runtime.)</p>