title: Custom Java classloader and inner classes
body: <p>I have this method (in my own classloader) that loads classes from zip:</p>
  
  <pre><code>ZipInputStream in = new ZipInputStream(new FileInputStream(zip));
  ZipEntry entry;
  while ((entry = in.getNextEntry()) != null) {
      if (!entry.isDirectory()) {
          byte[] buffer = new byte[(int) entry.getSize()];
          in.read(buffer);
          if (!entry.getName().endsWith(".class"))
              continue;
          String name = entry.getName().replace(".class", "").replace("/", ".");
          Class&lt;?&gt; cls = this.defineClass(name, buffer, 0, buffer.length);
          this.resolveClass(cls);
      }
  }
  </code></pre>
  
  <p>The zip that im trying to load looks like this:</p>
  
  <pre><code>TestClass.class
  TestClass$SomeOtherInnerClass.class 
  </code></pre>
  
  <p>My problem is that defineClass() fails to load the TestClass$SomeOtherInnerClass. If this class is loaded before the actual TestClass i get this:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: TestClass
  </code></pre>
  
  <p>I also tried to load the TestClass.class first but then im getting this error:</p>
  
  <pre><code>java.lang.ClassFormatError: Wrong InnerClasses attribute length in class file TestClass 
  </code></pre>
  
  <p>Is there something i'm doing wrong?</p>