title: Generating interface with ASM is not working
body: <p>I need to generate an interface at runtime. This interface will be used in a <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Proxy.html" rel="nofollow">dynamic proxy</a>. At first, I found <a href="http://weblogs.java.net/blog/emcmanus/archive/2006/10/build_your_own.html" rel="nofollow">this article</a> from Google, but then I found I could just use <a href="http://asm.ow2.org/" rel="nofollow">ASM</a> instead. Here is my code that gets the bytecode of the interface:</p>
  
  <pre><code>private static byte[] getBytecode(String internalName, String genericClassTypeSignature, Method[] methods, Class&lt;?&gt;... extendedInterfaces) throws IOException {
      ClassWriter cw = new ClassWriter(0);
      String[] interfaces = new String[extendedInterfaces.length];
      int i = 0;
      for (Class&lt;?&gt; interfac : extendedInterfaces) {
          interfaces[i] = interfac.getName().replace('.', '/');
          i++;
      }
      cw.visit(V1_6, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, internalName, null, "java/lang/Object", interfaces);
      ArrayList&lt;String&gt; exceptions = new ArrayList&lt;String&gt;();
      for (Method m : methods) {
          exceptions.clear();
          for (Class&lt;?&gt; exception : m.getExceptionTypes()) {
              exceptions.add(getInternalNameOf(exception));
          }
          cw.visitMethod(removeInvalidAbstractModifiers(m.getModifiers()) + ACC_ABSTRACT, m.getName(), getMethodDescriptorOf(m), getTypeSignatureOf(m), exceptions.toArray(new String[exceptions.size()]));
      }
      cw.visitEnd();
      return cw.toByteArray();
  }
  
  private static int removeInvalidAbstractModifiers(int mod) {
      int result = 0;
      if (Modifier.isProtected(mod)) {
          result += ACC_PROTECTED;
      }
      if (Modifier.isPublic(mod)) {
          result += ACC_PUBLIC;
      }
      if (Modifier.isTransient(mod)) {
          result += ACC_VARARGS;
      }
      return result;
  }
  </code></pre>
  
  <p>Just for test purposes, I tried to convert JFrame to an interface. But when I load my generated interface, it gives me a <code>java.lang.ClassFormatError</code>:</p>
  
  <pre><code>java.lang.ClassFormatError: Method paramString in class javax/swing/JFrame$GeneratedInterface has illegal modifiers: 0x404
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
      // ...
  </code></pre>
  
  <p><code>Modifier.toString(0x404)</code> tells me that <code>0x404</code> means <code>protected abstract</code>. As far as I know, a <code>protected abstract</code> method in an <code>abstract</code> class is perfectly legal.</p>
  
  <p>Here is the code for the <code>paramString</code> method (see above) in <code>JFrame</code>:</p>
  
  <pre><code>/**
   * Returns a string representation of this &lt;code&gt;JFrame&lt;/code&gt;.
   * This method
   * is intended to be used only for debugging purposes, and the
   * content and format of the returned string may vary between
   * implementations. The returned string may be empty but may not
   * be &lt;code&gt;null&lt;/code&gt;.
   *
   * @return  a string representation of this &lt;code&gt;JFrame&lt;/code&gt;
   */
  protected String paramString() {
      String defaultCloseOperationString;
      if (defaultCloseOperation == HIDE_ON_CLOSE) {
          defaultCloseOperationString = "HIDE_ON_CLOSE";
      } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) {
          defaultCloseOperationString = "DISPOSE_ON_CLOSE";
      } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) {
          defaultCloseOperationString = "DO_NOTHING_ON_CLOSE";
      } else if (defaultCloseOperation == 3) {
          defaultCloseOperationString = "EXIT_ON_CLOSE";
      } else defaultCloseOperationString = "";
      String rootPaneString = (rootPane != null ?
                               rootPane.toString() : "");
      String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ?
                                              "true" : "false");
  
      return super.paramString() +
      ",defaultCloseOperation=" + defaultCloseOperationString +
      ",rootPane=" + rootPaneString +
      ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
  }
  </code></pre>
  
  <p>I see no reason why I should be getting this error. Could someone explain this to me?</p>