<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi list,<br>
      <br>
      I'm trying to use the ClassFile API to automatically implement
      control classes (as found in JavaFX). These classes define inner
      class CssMetaData implementations that refer back to the outer
      class, and the outer class refers to these implementations via
      static fields.  When I define one of the inner types using
      Lookup::defineClass I get a NoClassDefFoundError for the outer
      type.  When I define the outer type first, I get a
      NoClassDefFoundError for one of the inner types.  The situation is
      essentially this:</p>
    <div style="background-color:#ffffff;padding:0px 0px 0px 2px;">
      <div
style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:11pt;white-space:pre;"><p
      style="margin:0;"><span style="color:#000000;">    </span><span
      style="color:#0000a0;font-weight:bold;">public</span><span
      style="color:#000000;"> </span><span
      style="color:#0000a0;font-weight:bold;">class</span><span
      style="color:#000000;"> Sample {</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span
      style="color:#0000a0;font-weight:bold;">private</span><span
      style="color:#000000;"> </span><span
      style="color:#0000a0;font-weight:bold;">final</span><span
      style="color:#000000;"> Property </span><span
      style="color:#0000c0;">b</span><span style="color:#000000;"> = </span><span
      style="color:#0000a0;font-weight:bold;">new</span><span
      style="color:#000000;"> Property(</span><span
      style="color:#0000c0;">A</span><span style="color:#000000;">);</span></p><p
      style="margin:0;"><span style="color:#000000;">    </span></p><p
      style="margin:0;"><span style="color:#000000;">      </span><span
      style="color:#0000a0;font-weight:bold;">private</span><span
      style="color:#000000;"> </span><span
      style="color:#0000a0;font-weight:bold;">static</span><span
      style="color:#000000;"> </span><span
      style="color:#0000a0;font-weight:bold;">final</span><span
      style="color:#000000;"> CssMetaData </span><span
      style="color:#0000c0;">A</span><span style="color:#000000;"> = </span><span
      style="color:#0000a0;font-weight:bold;">new</span><span
      style="color:#000000;"> CssMetaData() {</span></p><p
      style="margin:0;"><span style="color:#000000;">        </span><span
      style="color:#646464;">@Override</span></p><p style="margin:0;"><span
      style="color:#000000;">        </span><span
      style="color:#0000a0;font-weight:bold;">public</span><span
      style="color:#000000;"> Property getProperty(Object obj) {</span></p><p
      style="margin:0;"><span style="color:#000000;">          </span><span
      style="color:#7f0055;font-weight:bold;">return</span><span
      style="color:#000000;"> ((Sample)obj).</span><span
      style="color:#0000c0;">b</span><span style="color:#000000;">;</span></p><p
      style="margin:0;"><span style="color:#000000;">        }</span></p><p
      style="margin:0;"><span style="color:#000000;">      };</span></p><p
      style="margin:0;"><span style="color:#000000;">    }</span></p><p
      style="margin:0;">
</p><p style="margin:0;"><span style="color:#000000;">    </span><span
      style="color:#0000a0;font-weight:bold;">abstract</span><span
      style="color:#000000;"> </span><span
      style="color:#0000a0;font-weight:bold;">class</span><span
      style="color:#000000;"> CssMetaData {</span></p><p
      style="margin:0;"><span style="color:#000000;">      </span><span
      style="color:#0000a0;font-weight:bold;">abstract</span><span
      style="color:#000000;"> Property getProperty(Object obj);</span></p><p
      style="margin:0;"><span style="color:#000000;">    }</span></p><p
      style="margin:0;"><span style="color:#000000;">  </span></p><p
      style="margin:0;"><span style="color:#000000;">    </span><span
      style="color:#0000a0;font-weight:bold;">class</span><span
      style="color:#000000;"> Property {</span></p><p style="margin:0;"><span
      style="color:#000000;">      </span><span
      style="color:#0000a0;font-weight:bold;">public</span><span
      style="color:#000000;"> Property(CssMetaData </span><span
style="color:#000000;text-decoration:underline;text-decoration-color:#f4c82d;text-decoration-style:wavy;">a</span><span
      style="color:#000000;">) {</span></p><p style="margin:0;"><span
      style="color:#000000;">      }</span></p><p style="margin:0;"><span
      style="color:#000000;">    }</span></p></div>
    </div>
    <p></p>
    <p>I'm trying to generate the Sample class.  The classes CssMetaData
      and Propery are pre-existing.  As you can see, Sample refers to A
      in a property it creates, while A refers to that property by
      direct field access after a cast.</p>
    <p>Note that the above is perfectly legal as a Java class, and I
      think the bytecode I generate is correct.  It seems I would need
      to be able to define both classes at the same time, but Lookup
      doesn't seem to have anything for this purpose.</p>
    <p>I'd appreciate any insights!</p>
    <p>--John<br>
    </p>
    <p></p>
  </body>
</html>